This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Test for the import lock
Type: Stage: resolved
Components: Interpreter Core, Tests Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, ncoghlan, pitrou
Priority: normal Keywords: patch

Created on 2010-07-13 19:05 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mtimport.py pitrou, 2010-07-13 19:06
Messages (10)
msg110219 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-13 19:05
The import lock is lacking tests that it functions properly.

Coming up with a way of checking it was unexpectedly hard. I finally managed to write a script which quite reliably fails if you patch Python/import.c to not take the import lock. The script relies on garbage collection trickery to release the GIL at arbitrary moments.
It should probably be converted to an unit test.
msg110226 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-07-13 20:54
test_threaded_import is designed to check the import lock (and it does
at least to some degree - I changed runpy's handling of the import
lock because my original approach broke that test).

(Haven't looked at this patch in detail as yet)
msg110263 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-14 10:46
> test_threaded_import is designed to check the import lock (and it does
> at least to some degree - I changed runpy's handling of the import
> lock because my original approach broke that test).

Apparently, Lib/test/test_threaded_import only works if run directly. If
run through regrtest, it succeeds even with the import lock disabled
(probably because random.py is already included by regrtest).
msg110267 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-14 11:27
Ok, here is a patch for test_threaded_import that makes it work for regrtest too. I've removed all global variables and converted it to unittest.
msg110269 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-14 11:57
I've committed the fix in r82885 (3.2) and r82886 (3.1). The reliance on random still looks a bit quirky to me, but at least the test now does what it should do, and has a cleaned up coding style.

I'm leaving this issue open, for the other test might be interesting to integrate as well.
msg110294 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-14 16:11
Here is another patch that also tests that calls to path hooks and meta_path entries are serialized. Again, they pass in normal conditions and fail when the import lock is disabled.
msg114540 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-21 18:41
Ping?
msg114643 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-08-22 08:24
With the new setUp and tearDown methods, the threadedimp2 patch doesn't apply cleanly any more.

Looks good and passes for me - fixed patch attached.

Was I meant to still be looking at mtimport or threadimp, or have both of those been applied?
msg114658 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-22 10:12
> Was I meant to still be looking at mtimport or threadimp, or have both 
> of those been applied?

threadimp has already been committed.
As for mtimport, I'll try to refactor it into a proper unit test.
msg114662 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-22 10:19
The new patch was committed in r84258, thanks Nick.
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53497
2012-05-16 16:10:58pitrousetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2010-08-22 10:19:21pitrousetfiles: - issue9251_threadimp_py3k_head.patch
2010-08-22 10:19:18pitrousetfiles: - threadimp2.patch
2010-08-22 10:19:15pitrousetfiles: - threadimp.patch
2010-08-22 10:19:06pitrousetmessages: + msg114662
2010-08-22 10:12:47pitrousetmessages: + msg114658
2010-08-22 08:24:51ncoghlansetfiles: + issue9251_threadimp_py3k_head.patch

messages: + msg114643
2010-08-21 18:41:40pitrousetmessages: + msg114540
2010-07-14 16:11:37pitrousetfiles: + threadimp2.patch

messages: + msg110294
2010-07-14 11:57:24pitrousetmessages: + msg110269
2010-07-14 11:27:10pitrousetfiles: + threadimp.patch
keywords: + patch
messages: + msg110267
2010-07-14 10:46:00pitrousetmessages: + msg110263
2010-07-13 20:54:23ncoghlansetmessages: + msg110226
2010-07-13 19:06:59pitrousetfiles: + mtimport.py
2010-07-13 19:06:52pitrousetfiles: - mtimport.py
2010-07-13 19:05:30pitroucreate