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

Replace deprecated imp module with importlib #145

Closed
hugovk opened this issue May 8, 2023 · 2 comments · Fixed by #147
Closed

Replace deprecated imp module with importlib #145

hugovk opened this issue May 8, 2023 · 2 comments · Fixed by #147

Comments

@hugovk
Copy link

hugovk commented May 8, 2023

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

@itamarst
Copy link
Owner

itamarst commented May 8, 2023

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

@itamarst
Copy link
Owner

itamarst commented May 8, 2023

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants