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

_dummy_thread lacks an RLock implementaiton #80869

Closed
tirkarthi opened this issue Apr 21, 2019 · 9 comments
Closed

_dummy_thread lacks an RLock implementaiton #80869

tirkarthi opened this issue Apr 21, 2019 · 9 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tirkarthi
Copy link
Member

BPO 36688
Nosy @brettcannon, @pitrou, @vstinner, @ned-deily, @miss-islington, @tirkarthi
PRs
  • bpo-36688: Adding an implementation of RLock in _dummy_thread #12943
  • [3.7] bpo-36688: Adding an implementation of RLock in _dummy_thread (GH-12943) #14144
  • [3.8] bpo-36688: Adding an implementation of RLock in _dummy_thread (GH-12943) #14145
  • 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:

    assignee = None
    closed_at = <Date 2019-06-17.08:44:28.427>
    created_at = <Date 2019-04-21.06:20:08.559>
    labels = ['easy', 'type-bug', '3.8', '3.9', '3.7', 'library']
    title = '_dummy_thread lacks an RLock implementaiton'
    updated_at = <Date 2019-06-17.08:44:28.426>
    user = 'https://github.com/tirkarthi'

    bugs.python.org fields:

    activity = <Date 2019-06-17.08:44:28.426>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-06-17.08:44:28.427>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2019-04-21.06:20:08.559>
    creator = 'xtreak'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36688
    keywords = ['patch', 'easy', '3.7regression']
    message_count = 9.0
    messages = ['340597', '340681', '345804', '345812', '345813', '345814', '345819', '345820', '345823']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'pitrou', 'vstinner', 'ned.deily', 'miss-islington', 'xtreak']
    pr_nums = ['12943', '14144', '14145']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36688'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @tirkarthi
    Copy link
    Member Author

    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")'
    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)

    @tirkarthi tirkarthi added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 21, 2019
    @brettcannon
    Copy link
    Member

    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.

    @brettcannon brettcannon changed the title import dummy_threading causes ImportError _dummy_thread lacks an RLock implementaiton Apr 22, 2019
    @ned-deily
    Copy link
    Member

    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?

    @ned-deily ned-deily added the 3.9 only security fixes label Jun 17, 2019
    @vstinner
    Copy link
    Member

    I created bpo-37312: "Remove deprecated _dummy_thread and dummy_threading modules" (in Python 3.9).

    @vstinner
    Copy link
    Member

    New changeset c5905f3 by Victor Stinner (Joost Lek) in branch 'master':
    bpo-36688: Adding an implementation of RLock in _dummy_thread (GH-12943)
    c5905f3

    @vstinner
    Copy link
    Member

    Ping. This was marked as a 3.7regression and there is a PR waiting for review.

    PR 12943 seems reasonable to me. I merged it.

    Do we have plans to remove _dummy_thread in 3.8 or 3.9?

    I created bpo-37312 for Python 3.9. IMHO it's too late for 3.8.

    @miss-islington
    Copy link
    Contributor

    New changeset 351b0e7 by Miss Islington (bot) in branch '3.7':
    bpo-36688: Adding an implementation of RLock in _dummy_thread (GH-12943)
    351b0e7

    @miss-islington
    Copy link
    Contributor

    New changeset ad50591 by Miss Islington (bot) in branch '3.8':
    bpo-36688: Adding an implementation of RLock in _dummy_thread (GH-12943)
    ad50591

    @vstinner
    Copy link
    Member

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants