python-trio / trio-asyncio

a re-implementation of the asyncio mainloop on top of Trio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with thread pool cleanup

smurfix opened this issue · comments

The test tests/python/test_events.py::TrioEventLoopTests::test_get_event_loop_new_process consistently stalls for ten seconds when it ends.
The reason is that the pool thread sits on a queue

(gdb) py-bt
Traceback (most recent call first):
  <built-in method acquire of _thread.lock object at remote 0x7fbc1a857990>
  File "/usr/lib/python3.6/threading.py", line 295, in wait
    waiter.acquire()
  File "/usr/lib/python3.6/queue.py", line 164, in get
    self.not_empty.wait()
  (frame information optimized out)
  <built-in method send of coroutine object at remote 0x7fbc1a883518>
  File "/src/trio/trio/_core/_run.py", line 1336, in run_impl
    msg = task.coro.send(next_send)
  File "/src/trio/trio/_core/_run.py", line 1218, in run
    result = run_impl(runner, async_fn, args)
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 884, in _bootstrap
    self._bootstrap_inner()

while the main thread is already trying to shut down and waits for the pool thread to exit

(gdb) py-bt
Traceback (most recent call first):
  <built-in method sleep of module object at remote 0x7fbc1e6cf908>
  File "/usr/lib/python3.6/test/support/__init__.py", line 2074, in threading_cleanup
    time.sleep(0.01)
  File "/src/trio-asyncio/asyncio/test_utils.py", line 478, in tearDown
    support.threading_cleanup(*self._thread_cleanup)
  File "/src/trio-asyncio/tests/python/test_events.py", line 269, in tearDown
    super().tearDown()
  File "/src/trio-asyncio/tests/python/test_events.py", line 2205, in tearDown
    super().tearDown()
  File "/usr/lib/python3.6/unittest/case.py", line 608, in run
    self.tearDown()
  File "/usr/lib/python3.6/unittest/case.py", line 653, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python3/dist-packages/_pytest/unittest.py", line 176, in runtest
    self._testcase(result=self)
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 112, in pytest_runtest_call
    item.runtest()
…

Found it. commit e063725