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

Is watchdog safe to run without GIL? #1089

Open
tokeefe opened this issue Dec 2, 2024 · 2 comments
Open

Is watchdog safe to run without GIL? #1089

tokeefe opened this issue Dec 2, 2024 · 2 comments

Comments

@tokeefe
Copy link

tokeefe commented Dec 2, 2024

When running watchdog under Python 3.13t (with the GIL disabled), Python re-enables the GIL and prints the following warning

<frozen importlib._bootstrap>:488: RuntimeWarning: The global interpreter 
lock (GIL) has been enabled to load module '_watchdog_fsevents', which has 
not declared that it can run safely without the GIL. To override this behavior and 
keep the GIL disabled (at your own risk), run with PYTHON_GIL=0 or -Xgil=0.

At a glance, some basic watchdog applications seem to run properly with the GIL disabled. I also ran the test suite on macOS, which passed (at least no additional XPASS or warnings)

python3.13t -Xgil=0 -m tox -q -e py
...
163 passed, 10 skipped, 2 xpassed, 1 warning in 92.15s (0:01:32)
py: OK (94.21 seconds)
congratulations :) (94.33 seconds)

P.S. - After a quick search, it looks as though GitHub Actions is actively working on exposing a new Python version 3.13t that will allow developers to run tests with free-threading enabled. I'm not sure if this is available quite yet, but should be close.

@tokeefe tokeefe changed the title Declare watchdog safe to run without GIL Is watchdog safe to run without GIL? Dec 2, 2024
@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 2, 2024

I would be more confident to change the C code when it will be possible to run tests on the CI, as you noted 👍

Note that I do not anymore own a Mac machine to work on that stuff, so if you have some C skills, please be my guest :)

@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 5, 2024

Concerned code:

/* Acquire interpreter lock and save original thread state. */
PyGILState_STATE gil_state = PyGILState_Ensure();
saved_thread_state = PyThreadState_Swap(stream_callback_info_ref->thread_state);

/* Release the lock and restore thread state. */
PyThreadState_Swap(saved_thread_state);
PyGILState_Release(gil_state);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants