pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.98k stars 2.66k forks source link

pytest hangs on waiter.acquire() - (FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME) #10684

Closed 86Ilya closed 1 year ago

86Ilya commented 1 year ago

Example with dockerfile

docker build -t check-pytest .
docker run -it check-pytest

I'm not sure but it's looks like python wait for coroutine ending in wrong event loop.

The-Compiler commented 1 year ago

Here is the full trace from -o faulthandler_timeout=5:

Thread 0x00007fa889bdf700 (most recent call first):
  File "/usr/local/lib/python3.9/selectors.py", line 469 in select
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1869 in _run_once
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 601 in run_forever
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 634 in run_until_complete
  File "/usr/local/lib/python3.9/asyncio/runners.py", line 44 in run
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 292 in run
  File "/usr/local/lib/python3.9/site-packages/anyio/_core/_eventloop.py", line 70 in run
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58 in run
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 83 in _worker
  File "/usr/local/lib/python3.9/threading.py", line 917 in run
  File "/usr/local/lib/python3.9/threading.py", line 980 in _bootstrap_inner
  File "/usr/local/lib/python3.9/threading.py", line 937 in _bootstrap

Thread 0x00007fa88d8d7740 (most recent call first):
  File "/usr/local/lib/python3.9/threading.py", line 312 in wait
  File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 441 in result
  File "/usr/local/lib/python3.9/site-packages/anyio/from_thread.py", line 283 in call
  File "/usr/local/lib/python3.9/site-packages/starlette/testclient.py", line 334 in handle_request
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1009 in _send_single_request
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 973 in _send_handling_redirects
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 936 in _send_handling_auth
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 908 in send
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 821 in request
  File "/usr/local/lib/python3.9/site-packages/starlette/testclient.py", line 454 in request
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1136 in post
  File "/usr/local/lib/python3.9/site-packages/starlette/testclient.py", line 579 in post
  File "/app/tests/test_views.py", line 12 in test_credentials_is_correct
  File "/usr/local/lib/python3.9/site-packages/_pytest/python.py", line 195 in pytest_pyfunc_call
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/usr/local/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/usr/local/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/usr/local/lib/python3.9/site-packages/_pytest/python.py", line 1789 in runtest
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 167 in pytest_runtest_call
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/usr/local/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/usr/local/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 260 in <lambda>
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 339 in from_call
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 259 in call_runtest_hook
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 220 in call_and_report
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 131 in runtestprotocol
  File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 112 in pytest_runtest_protocol
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/usr/local/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/usr/local/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 349 in pytest_runtestloop
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/usr/local/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/usr/local/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 324 in _main
  File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 270 in wrap_session
  File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 317 in pytest_cmdline_main
  File "/usr/local/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/usr/local/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/usr/local/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py", line 167 in main
  File "/usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py", line 190 in console_main
  File "/usr/local/lib/python3.9/site-packages/pytest/__main__.py", line 5 in <module>
  File "/usr/local/lib/python3.9/runpy.py", line 87 in _run_code
  File "/usr/local/lib/python3.9/runpy.py", line 197 in _run_module_as_main

pytest itself doesn't deal with threading or asyncio, and as you can see, the pytest main thread hangs while calling into starlette.testclient / httpx.client / anyio - so this doesn't seem like a pytest issue. I'm converting this into a Q&A discussion, maybe someone has an idea what's going on.