コード例 #1
0
 def open(self):
     """Open TCP connection."""
     ret = super(AsyncioInThreadTerminal, self).open()
     thread4async = get_asyncio_loop_thread()
     thread4async.run_async_coroutine(self._async_terminal.open(), timeout=600.5)  # await initial prompt may be longer
     # no need for 'def send()' in this class since sending goes via moler connection
     # after open() here, moler connection will be bound to data path running inside dedicated thread
     # same for 'def data_received()' - will get data from self._async_terminal
     return ret
コード例 #2
0
    def close(self):
        """
        Close TCP connection.

        Connection should allow for calling close on closed/not-open connection.
        """
        if self._async_terminal._transport:  # change it to coro is_open() checked inside async-thread
            # self._debug('closing {}'.format(self))
            thread4async = get_asyncio_loop_thread()
            ret = thread4async.run_async_coroutine(self._async_terminal.close(), timeout=0.5)
コード例 #3
0
def test_can_get_same_asyncio_loop_thread_even_from_different_calling_threads():
    from moler.asyncio_runner import get_asyncio_loop_thread
    async_thrds = [None, None, None]
    async_thrds[0] = get_asyncio_loop_thread()  # first one must be called from MainThread (unix signals issue)

    def call_from_thrd0():
        async_thrds[1] = get_asyncio_loop_thread()

    def call_from_thrd1():
        async_thrds[2] = get_asyncio_loop_thread()

    thrd0 = threading.Thread(target=call_from_thrd0)
    thrd1 = threading.Thread(target=call_from_thrd1)

    thrd0.start()
    thrd1.start()
    time.sleep(0.1)  # allow threads switch
    assert async_thrds[1] is not None
    assert async_thrds[0] is async_thrds[1]
    assert async_thrds[1] is async_thrds[2]
コード例 #4
0
ファイル: tcp.py プロジェクト: nokia/moler
 def open(self):
     """Open TCP connection."""
     ret = super(AsyncioInThreadTcp, self).open()
     thread4async = get_asyncio_loop_thread()
     thread4async.run_async_coroutine(self._async_tcp.open(), timeout=0.5)
     return ret
コード例 #5
0
def test_get_asyncio_loop_thread_returns_running_thread_and_loop():
    from moler.asyncio_runner import get_asyncio_loop_thread

    async_thrd = get_asyncio_loop_thread()
    assert async_thrd.is_alive()
    assert async_thrd.ev_loop.is_running()
コード例 #6
0
 def call_from_thrd1():
     async_thrds[2] = get_asyncio_loop_thread()
コード例 #7
0
 def call_from_thrd0():
     async_thrds[1] = get_asyncio_loop_thread()
コード例 #8
0
def test_can_get_same_asyncio_loop_thread():
    from moler.asyncio_runner import get_asyncio_loop_thread

    async_thrd_1 = get_asyncio_loop_thread()
    async_thrd_2 = get_asyncio_loop_thread()
    assert async_thrd_1 == async_thrd_2