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
_dummy_thread lacks an RLock implementaiton #80869
Comments
importing dummy_threading causes ImportError. It used to work on 3.6. There are tests at Lib/test/test_dummy_threading.py and rearranging the import so that "import dummy_threading as _threading" is the first line also causes error. This module was deprecated from 3.7 with respect to threading enabled always but I thought to add a report anyway. Looking at git log it seems a6a4dc8 did some changes where catching the ImportError on Lib/functools.py was removed that could be causing this issue. Importing functools before dummy_threading works. # master with functools imported before dummy_threading ➜ cpython git:(master) ✗ ./python.exe -c 'import functools; import dummy_threading; print("hello")' # Python 3.6 $ python3.6 -c 'import dummy_threading; print("hello")'
hello # Python 3.7 $ python3.7 -c 'import dummy_threading'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/dummy_threading.py", line 45, in <module>
import threading
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 8, in <module>
from traceback import format_exc as _format_exc
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/traceback.py", line 5, in <module>
import linecache
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/linecache.py", line 8, in <module>
import functools
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/functools.py", line 24, in <module>
from _thread import RLock
ImportError: cannot import name 'RLock' from '_dummy_thread' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_dummy_thread.py) # master $ cpython git:(master) ./python.exe -c 'import dummy_threading'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/dummy_threading.py", line 45, in <module>
import threading
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/threading.py", line 8, in <module>
from traceback import format_exc as _format_exc
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/traceback.py", line 5, in <module>
import linecache
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/linecache.py", line 8, in <module>
import functools
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/functools.py", line 20, in <module>
from _thread import RLock
ImportError: cannot import name 'RLock' from '_dummy_thread' (/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/_dummy_thread.py) # Patch to move dummy_threading import as first line diff --git a/Lib/test/test_dummy_threading.py b/Lib/test/test_dummy_threading.py
index a0c2972a60..dc40abeda5 100644
--- a/Lib/test/test_dummy_threading.py
+++ b/Lib/test/test_dummy_threading.py
@@ -1,6 +1,6 @@
+import dummy_threading as _threading
from test import support
import unittest
-import dummy_threading as _threading
import time class DummyThreadingTestCase(unittest.TestCase): ➜ cpython git:(master) ✗ ./python.exe Lib/test/test_dummy_threading.py
Traceback (most recent call last):
File "Lib/test/test_dummy_threading.py", line 1, in <module>
import dummy_threading as _threading
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/dummy_threading.py", line 45, in <module>
import threading
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/threading.py", line 8, in <module>
from traceback import format_exc as _format_exc
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/traceback.py", line 5, in <module>
import linecache
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/linecache.py", line 8, in <module>
import functools
File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/functools.py", line 20, in <module>
from _thread import RLock
ImportError: cannot import name 'RLock' from '_dummy_thread' (/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/_dummy_thread.py) |
Basically _thread.RLock was added without an equivalent in _dummy_thread. Add that and it will fix the issue. It probably wouldn't be too hard since you have to implement it as if it's single-threaded and there's already a lock class in _dummy_thread to work off of. Heck, functools used to have its own dummy version in a6a4dc8 but it got ripped out, although it was extremely basic so I don't know if it would be the best version to put into _dummy_thread. |
Ping. This was marked as a 3.7regression and there is a PR waiting for review. Do we have plans to remove _dummy_thread in 3.8 or 3.9? |
I created bpo-37312: "Remove deprecated _dummy_thread and dummy_threading modules" (in Python 3.9). |
Thanks Joost Lek for the fix and Karthikeyan Singaravelan for the bug report. It's now fixed in 3.7, 3.8 and master branches. I close the issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: