Skip to content
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

SystemError using yappy for Python3.13 Free Threaded #179

Open
dan-glass opened this issue Nov 4, 2024 · 0 comments
Open

SystemError using yappy for Python3.13 Free Threaded #179

dan-glass opened this issue Nov 4, 2024 · 0 comments

Comments

@dan-glass
Copy link

dan-glass commented Nov 4, 2024

I am having trouble getting Yappi to work with Python 3.13t Free Threading. Attempting to isolate the issue, the smallest example was using unittest.patch. However I am able to see it with other libraries, notably a c binary accessed via ctypes. The issue occurs whether the GI is disabled or not.

Code

#!/usr/bin/env python3.13t
import yappi
import unittest
from unittest.mock import patch
import sys
print(sys.version)

class TestReadFile(unittest.TestCase):

    def setUp(self):
        yappi.start()

    @patch('builtins.open')
    def test_read_file(self, mock_file):
        pass


if __name__ == '__main__':
    unittest.main()

Command

./test_yappi.py
PYTHON_GIL=1 ./test_yappi.py

Output

# ./test_yappi.py
3.13.0 experimental free-threading build (main, Oct  8 2024, 08:51:27) [GCC 9.4.0]
E
======================================================================
ERROR: test_read_file (__main__.TestReadFile.test_read_file)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.13/unittest/mock.py", line 686, in __getattr__
    elif self._mock_methods is not None:
         ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/unittest/mock.py", line 685, in __getattr__
    raise AttributeError(name)
AttributeError: _mock_methods

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.13/unittest/mock.py", line 1420, in patched
    with self.decoration_helper(patched,
         ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
                                args,
                                ^^^^^
                                keywargs) as (newargs, newkeywargs):
                                ^^^^^^^^^
  File "/usr/lib/python3.13/contextlib.py", line 141, in __enter__
    return next(self.gen)
  File "/usr/lib/python3.13/unittest/mock.py", line 1402, in decoration_helper
    arg = exit_stack.enter_context(patching)
  File "/usr/lib/python3.13/contextlib.py", line 530, in enter_context
    result = _enter(cm)
  File "/usr/lib/python3.13/unittest/mock.py", line 1549, in __enter__
    new = Klass(**_kwargs)
  File "/usr/lib/python3.13/unittest/mock.py", line 2156, in __init__
    def __init__(self, /, *args, **kw):

SystemError: <sys.legacy_event_handler object at 0x48614a4a950> returned a result with an exception set

----------------------------------------------------------------------
Ran 1 test in 0.005s

FAILED (errors=1)

Dockerfile

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN add-apt-repository -y ppa:deadsnakes/ppa
RUN apt-get install -y \
    	python3.13-nogil \
    	libpython3.13-nogil \
    	libpython3.13-dev
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

No branches or pull requests

1 participant