<commit_before>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import rapidsms.component

class Backend(rapidsms.component.Component):
    def __init__ (self, router):
        self.router = router
        self.running = False

    def start(self):
        self.running = True
        try:
            self.run()
        finally:
            self.running = False

    def run (self):
        raise NotImplementedError
    
    def stop(self):
        self.running = False
    
    def send(self):
        raise NotImplementedError
    
    def receive(self):
        raise NotImplementedError<commit_msg>Added message queueing on send to Backend.<commit_after>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import rapidsms.component
import Queue

class Backend(rapidsms.component.Component):
    def __init__ (self, router):
        self.router     = router
        self._running   = False
        # do we want to put a limit on the queue size?
        # and what do we do if the queue gets full?
        self._queue     = Queue.Queue()

    @property
    def running (self):
        return self._running

    def start(self):
        self._running = True
        try:
            self.run()
        finally:
            self._running = False

    def run (self):
        raise NotImplementedError
    
    def stop(self):
        self._running = False
    
    def send(self, message):
        # block until we can add to the queue.
        # it shouldn't be that long.
        self._queue.put(message, True)
    
    def receive(self, caller, text):
        # turn the caller/text into a message object
        msg = Message(self, caller, text)
        # and send it off to the router
        self.router.incoming(msg)
    
    def has_outgoing (self):
        return self._queue.qsize()
 
    def outgoing (self):
        try:
            return self._queue.get_nowait()
        except Queue.Empty:
            return None
{'fraction_non_alphanumeric': 0.08432488360062079, 'fraction_numerical': 0.0031039834454216243, 'mean_word_length': 1.8952095808383234, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4801433', 'n_tokens_mistral': 566, 'n_tokens_neox': 556, 'n_words': 176}