Skip to content

Compensate for asyncio changes in Python 3.13.3/3.14 #662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2025

Conversation

cjwatson
Copy link
Contributor

In
python/cpython@38a9956 (backported to 3.13 as
python/cpython@7b0543e), Python moved the responsibility for setting the task name from asyncio.create_task to the Task constructor. While uvloop itself is unaffected, this causes test_set_task_name to fail when run with asyncio. Compensate for that in this particular test.

It's possible that uvloop's behaviour should be changed to match asyncio's depending on the Python version, but that seems like a more involved change. For now, this at least gets the tests passing again.

Most of this analysis and patch were from Martin Hostettler in https://bugs.debian.org/1101258#24; I just tweaked the patch slightly to ensure it still passes on older Python versions.

In
python/cpython@38a9956
(backported to 3.13 as
python/cpython@7b0543e),
Python moved the responsibility for setting the task name from
`asyncio.create_task` to the `Task` constructor.  While `uvloop` itself
is unaffected, this causes `test_set_task_name` to fail when run with
`asyncio`.  Compensate for that in this particular test.

It's possible that `uvloop`'s behaviour should be changed to match
`asyncio`'s depending on the Python version, but that seems like a more
involved change.  For now, this at least gets the tests passing again.

Most of this analysis and patch were from Martin Hostettler in
https://bugs.debian.org/1101258#24; I just tweaked the patch slightly to
ensure it still passes on older Python versions.
@cjwatson cjwatson mentioned this pull request Apr 16, 2025
@cjwatson
Copy link
Contributor Author

The test failures seem unrelated to my change.

@hroncok
Copy link
Contributor

hroncok commented Apr 16, 2025

I'm testing this together with #658 applied in Fedora.

The remaining failures I get are:

=================================== FAILURES ===================================
________________ TestUVExecutors.test_executors_process_pool_01 ________________
Traceback (most recent call last):
  File "/usr/lib64/python3.14/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/lib64/python3.14/unittest/case.py", line 660, in run
    self._callTestMethod(testMethod)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/lib64/python3.14/unittest/case.py", line 606, in _callTestMethod
    result = method()
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_executors.py", line 35, in test_executors_process_pool_01
    self.run_pool_test(concurrent.futures.ProcessPoolExecutor)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_executors.py", line 29, in run_pool_test
    self.loop.run_until_complete(run())
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "uvloop/loop.pyx", line 1518, in uvloop.loop.Loop.run_until_complete
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_executors.py", line 24, in run
    res = await asyncio.gather(*coros)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
_______________ TestAIOExecutors.test_executors_process_pool_01 ________________
Traceback (most recent call last):
  File "/usr/lib64/python3.14/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/lib64/python3.14/unittest/case.py", line 660, in run
    self._callTestMethod(testMethod)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/lib64/python3.14/unittest/case.py", line 606, in _callTestMethod
    result = method()
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_executors.py", line 35, in test_executors_process_pool_01
    self.run_pool_test(concurrent.futures.ProcessPoolExecutor)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_executors.py", line 29, in run_pool_test
    self.loop.run_until_complete(run())
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/usr/lib64/python3.14/asyncio/base_events.py", line 719, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_executors.py", line 24, in run
    res = await asyncio.gather(*coros)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
___________________ TestIssue39Regr.test_issue39_regression ____________________
Traceback (most recent call last):
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_regr1.py", line 114, in test_issue39_regression
    self.run_test()
    ~~~~~~~~~~~~~^^
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_regr1.py", line 93, in run_test
    addr = qout.get()
  File "/usr/lib64/python3.14/multiprocessing/queues.py", line 101, in get
    res = self._recv_bytes()
  File "/usr/lib64/python3.14/multiprocessing/connection.py", line 222, in recv_bytes
    buf = self._recv_bytes(maxlength)
  File "/usr/lib64/python3.14/multiprocessing/connection.py", line 447, in _recv_bytes
    buf = self._recv(4)
  File "/usr/lib64/python3.14/multiprocessing/connection.py", line 412, in _recv
    chunk = read(handle, to_read)
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_regr1.py", line 74, in on_alarm
    raise FailedTestError
tests.test_regr1.FailedTestError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.14/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/lib64/python3.14/unittest/case.py", line 660, in run
    self._callTestMethod(testMethod)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/lib64/python3.14/unittest/case.py", line 606, in _callTestMethod
    result = method()
  File "/builddir/build/BUILD/python-uvloop-0.21.0-build/uvloop-0.21.0/_empty/tests/test_regr1.py", line 116, in test_issue39_regression
    self.fail('deadlocked in libuv')
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.14/unittest/case.py", line 741, in fail
    raise self.failureException(msg)
AssertionError: deadlocked in libuv

@1st1
Copy link
Member

1st1 commented Apr 16, 2025

@fantix our CI seem to consistently crash

fantix added 2 commits April 16, 2025 18:16
This was for Cython 3.0 beta to test with Python 3.13,
but it's now breaking our tests with Cython 3.1, while
Cython 3.0 stable is out.
@fantix fantix merged commit 96b7ed3 into MagicStack:master Apr 17, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants