def _control(task, timeout='60'): try: ts = time.time() logger.debug('http in -> /control/%s' % task) latch = ThreadingFuture() executor.tell({'request': task, 'latch': latch, 'data': request.data}) js, code = latch.get(timeout=int(timeout)) ms = time.time() - ts logger.debug('http out -> HTTP %s (%d ms)' % (code, ms)) return json.dumps(js), code except Timeout: # # - we failed to match the specified timeout # - gracefully fail on a HTTP 408 # return '{}', 408 except ActorDeadError: # # - the executor has been shutdown (probably after a /control/kill) # - gracefully fail on a HTTP 410 # return '{}', 410
def _control(task, timeout='60'): logger.debug('http in -> /control/%s' % task) if task not in ['check', 'on', 'off', 'ok', 'kill', 'signal']: # # - fail on a HTTP 400 if the request is not supported # return '{}', 400, {'Content-Type': 'application/json; charset=utf-8'} try: ts = time.time() latch = ThreadingFuture() executor.tell({'request': task, 'latch': latch, 'data': request.data}) js, code = latch.get(timeout=int(timeout)) ms = time.time() - ts logger.debug('http out -> HTTP %s (%d ms)' % (code, ms)) return json.dumps(js), code, {'Content-Type': 'application/json; charset=utf-8'} except Timeout: # # - we failed to match the specified timeout # - gracefully fail on a HTTP 408 # return '{}', 408, {'Content-Type': 'application/json; charset=utf-8'} except ActorDeadError: # # - the executor has been shutdown (probably after a /control/kill) # - gracefully fail on a HTTP 410 # return '{}', 410, {'Content-Type': 'application/json; charset=utf-8'}
def shutdown(actor_ref, timeout=None): """ Shuts a state-machine down and wait for it to acknowledge it's down using a latch. :type actor_ref: :class:`pykka.ActorRef` :param actor_ref: a pykka actor reference :type timeout: float :param timeout: optional timeout in seconds """ try: if not actor_ref: return latch = ThreadingFuture() actor_ref.tell({'request': 'shutdown', 'latch': latch}) Event() latch.get(timeout=timeout) except Timeout: pass except ActorDeadError: pass
def shutdown(actor_ref, timeout=None): """ Shuts a state-machine down and wait for it to acknowledge it's down using a latch. :type actor_ref: :class:`pykka.ActorRef` :param actor_ref: a pykka actor reference :type timeout: float :param timeout: optional timeout in seconds """ try: if not actor_ref: return latch = ThreadingFuture() actor_ref.tell({'request': 'shutdown', 'latch': latch}) Event() latch.get(timeout=timeout) except Timeout: pass except ActorDeadError: pass
def _control(task, timeout='60'): logger.debug('http in -> /control/%s' % task) if task not in ['check', 'on', 'off', 'ok', 'kill', 'signal']: # # - fail on a HTTP 400 if the request is not supported # return '{}', 400, { 'Content-Type': 'application/json; charset=utf-8' } try: ts = time.time() latch = ThreadingFuture() executor.tell({ 'request': task, 'latch': latch, 'data': request.data }) js, code = latch.get(timeout=int(timeout)) ms = time.time() - ts logger.debug('http out -> HTTP %s (%d ms)' % (code, ms)) return json.dumps(js), code, { 'Content-Type': 'application/json; charset=utf-8' } except Timeout: # # - we failed to match the specified timeout # - gracefully fail on a HTTP 408 # return '{}', 408, { 'Content-Type': 'application/json; charset=utf-8' } except ActorDeadError: # # - the executor has been shutdown (probably after a /control/kill) # - gracefully fail on a HTTP 410 # return '{}', 410, { 'Content-Type': 'application/json; charset=utf-8' }
def test_future_nested_future(future): inner_future = ThreadingFuture() inner_future.set("foo") outer_future = ThreadingFuture() outer_future.set(inner_future) assert outer_future.get().get() == "foo"