def __init__( self, name, hostport=None, process_name=None, known_peers=None, trace=False, threadloop=None, ): """Initialize a new TChannelClient. :param process_name: Name of the calling process. Used for logging purposes only. """ super(TChannel, self).__init__( name, hostport=hostport, process_name=process_name, known_peers=known_peers, trace=trace, ) self._threadloop = threadloop or ThreadLoop() self.advertise = self._wrap(self.advertise) self.raw = _SyncScheme(self.raw, self._threadloop) self.thrift = _SyncScheme(self.thrift, self._threadloop) self.json = _SyncScheme(self.json, self._threadloop)
def test_main_io_loop_is_not_changed(): threadloop = ThreadLoop() threadloop.start() # The ThreadLoop's IOLoop should not be the 'current' IOLoop in the main # thread. tl_loop = threadloop.submit(ioloop.IOLoop.current).result() assert ioloop.IOLoop.current() is not tl_loop
def _create_new_thread_loop(self): """ Create a daemonized thread that will run Tornado IOLoop. :return: the IOLoop backed by the new thread. """ self._thread_loop = ThreadLoop() if not self._thread_loop.is_ready(): self._thread_loop.start() return self._thread_loop._io_loop
def test_ioloop_is_not_already_running(): threadloop = ThreadLoop() threadloop.start() @gen.coroutine def f(): yield threadloop.submit(gen.sleep, 0.1) ioloop.IOLoop.current().run_sync(f)
def test_block_until_thread_is_ready(): threadloop = ThreadLoop() assert not threadloop.is_ready() threadloop.start() assert threadloop.is_ready()
def test_start_must_be_called_before_submit(): threadloop = ThreadLoop() @gen.coroutine def coroutine(): raise gen.Return("Hello World") with pytest.raises(ThreadNotStartedError): threadloop.submit(coroutine)
def __init__(self, name, process_name=None, known_peers=None, trace=False): """Initialize a new TChannelClient. :param process_name: Name of the calling process. Used for logging purposes only. """ self._async_client = async .TChannel(name, process_name=process_name, known_peers=known_peers, trace=trace) self._threadloop = ThreadLoop() self._threadloop.start()
def test_use_existing_ioloop(): io_loop = ioloop.IOLoop.current() threadloop = ThreadLoop(io_loop) assert threadloop._io_loop is io_loop @gen.coroutine def coroutine(): raise gen.Return("Hello World") with threadloop: future = threadloop.submit(coroutine) assert future.result() == "Hello World"
def test_is_not_ready_when_ready_hasnt_been_sent(): threadloop = ThreadLoop() threadloop._thread = True # fake the Thread being set assert not threadloop.is_ready()
def threadloop(): with ThreadLoop() as threadloop: yield threadloop