def receive(self, timeout=None): ''' Synchronously wait `timeout` seconds for a message. If a message arrives by then, return it, otherwise, raise a `Timeout`. ''' promise = get_pool().apply_async(self._receive) try: data = promise.get(timeout) except multiprocessing.TimeoutError: raise Timeout() else: return data
def send(self, recipient, message): ''' Asynchronously send `message` to `recipient` ''' get_pool().apply_async(self._send, (recipient, message))