I use the following function to make the coroutine work synchronously:
import asyncio import inspect import types from asyncio import BaseEventLoop from concurrent import futures def await_sync(coro: types.CoroutineType, timeout_s: int=None): """ :param coro: a coroutine or lambda loop: coroutine(loop) :param timeout_s: :return: """ loop = asyncio.new_event_loop()
However, intermittently, it will depend on the simple creation of a new loop: loop = asyncio.new_event_loop()
. Checking the stack traces shows me the exact place where it hangs:
File: "/src\system\utils.py", line 34, in await_sync loop = asyncio.new_event_loop() # type: BaseEventLoop File: "\lib\asyncio\events.py", line 636, in new_event_loop return get_event_loop_policy().new_event_loop() File: "\lib\asyncio\events.py", line 587, in new_event_loop return self._loop_factory() File: "\lib\asyncio\selector_events.py", line 55, in __init__ self._make_self_pipe() File: "\lib\asyncio\selector_events.py", line 116, in _make_self_pipe self._ssock, self._csock = self._socketpair() File: "\lib\asyncio\windows_events.py", line 295, in _socketpair return windows_utils.socketpair() File: "\lib\socket.py", line 515, in socketpair ssock, _ = lsock.accept() File: "\lib\socket.py", line 195, in accept fd, addr = self._accept()
What could be causing such a problem in a library as low as socket
? Am I doing something wrong? I am using Python 3.5.1.
Edit: I filed a bug report here , but Guido recommended that I continue to contact StackOverflow for help.
source share