Skip to content

Replace deprecated imp module with importlib #145

Closed

Description

@hugovk

This project's tests use the imp module which has been deprecated since Python 3.4 and removed in 3.12:

Python 3.12 is set for release on 2023-10-02 and this library is one of the top 5,000 most-downloaded from PyPI.

Please could you upgrade to use importlib? The imp docs have suggestions on what to use to replace each function and constant.

imp.acquire_lock()
lock_held.set()
test_complete.wait()
imp.release_lock()
t = threading.Thread(target=other_thread)
t.start()
lock_held.wait()
# While the imp lock is held by the other thread, we can't
# allow exceptions/assertions to happen because trial will
# try to do an import causing a deadlock instead of a
# failure. We collect all assertion pairs (result, expected),
# wait for the import lock to be released, and then check our
# assertions at the end of the test.
assertions = []
# we want to run .wait while the other thread has the lock acquired
assertions.append((imp.lock_held(), True))
try:
assertions.append((er.wait(0.1), 123))
finally:
test_complete.set()
assertions.append((imp.lock_held(), True))

Activity

  1. itamarst commented on May 8, 2023

    @itamarst
    Owner

    I should probably just delete that test, I suspect it's not really necessary in modern Python.

  2. itamarst commented on May 8, 2023

    @itamarst
    Owner

    Or just switch to importing a module with a sleep that runs at import time.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions