New submission from Karthikeyan Singaravelan <tir.kar...@gmail.com>:

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)

----------
components: Library (Lib)
messages: 340597
nosy: brett.cannon, pitrou, xtreak
priority: normal
severity: normal
status: open
title: import dummy_threading causes ImportError
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36688>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to