-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30599: Fix a refleak in test_threaded_import #2001
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
Conversation
@pitrou: It seems like you wrote some of test_threaded_import tests, especially test_side_effect_import(): commit ea3eb88, http://bugs.python.org/issue9260. Do you think that testing the availability of the types.ModuleType attribute is enough to check for non-regression? |
I don't think |
Lib/test/test_threaded_import.py
Outdated
# complains several times about module random having no attribute | ||
# randrange, and then Python hangs. | ||
# complains several times about module types having no attribute | ||
# ModuleType, and then Python hangs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it something that actually happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use less common module (e.g. |
Or, better, write a custom module that does a simplified version of what |
Since I don't undertand why was the import problem, I don't see how to write a module which would reproduce the bug. |
Fix reference leaks in test_threaded_import. Replace "import random" with "import colorsys" to avoid the following call of random.py, since "atfork" callbacks cannot be unregistered: os.register_at_fork(_inst.seed, when='child') Check that calling colorsys.rgb_to_hls() doesn't crash, rather than trying to call random.randrange().
Serhiy: "Could you use less common module (e.g. colorsys)?" Ok, done. I like colorsys since it has no dependency and its code is non-trivial. So we can keep a test trying to call a function (colorsys.rgb_to_hls()) of an imported module, rather than just testing if an attribute is available (types.ModuleType). Does it look better now? |
The problem is this isn't exercising anything anymore. |
Typically import a bunch of modules at top-level (just copy the imports done at the top of random.py), then create a singleton instance of something and bind one of its methods at the top-level, like random.py does. Then in the test, check you can call the top-level method. |
Hum, instead of cloning random.py "just to remove the os.register_at_fork() call", I chose a different approach which I already mention: #2029 only mocks os.register_at_fork() and so is less risky. |
Superseded by the PR #2029 which has been merged. |
Fix a reference leaks in test_threaded_import.
Replace "import random" with "import types" to avoid the following call of random.py, since "atfork" callbacks cannot be unregistered:
Check if types.ModuleType attribute is available, rather than trying to call random.randrange().