Message 340597 - Python tracker

Message340597

Author xtreak
Recipients brett.cannon, pitrou, xtreak
Date 2019-04-21.06:20:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555827608.59.0.767546227499.issue36688@roundup.psfhosted.org>
In-reply-to
Content
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 a6a4dc816d68df04a7d592e0b6af8c7ecc4d4344 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")'
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)
History
Date User Action Args
2019-04-21 06:20:08xtreaksetrecipients: + xtreak, brett.cannon, pitrou
2019-04-21 06:20:08xtreaksetmessageid: <1555827608.59.0.767546227499.issue36688@roundup.psfhosted.org>
2019-04-21 06:20:08xtreaklinkissue36688 messages
2019-04-21 06:20:08xtreakcreate