Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
69232348
Commit
69232348
authored
Aug 30, 2001
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a new function imp.lock_held(), and use it to skip test_threaded_import
when that test is doomed to deadlock.
parent
c4141875
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
4 deletions
+47
-4
Doc/lib/libimp.tex
Doc/lib/libimp.tex
+13
-0
Lib/test/test_threaded_import.py
Lib/test/test_threaded_import.py
+6
-4
Misc/NEWS
Misc/NEWS
+9
-0
Python/import.c
Python/import.c
+19
-0
No files found.
Doc/lib/libimp.tex
View file @
69232348
...
...
@@ -93,6 +93,19 @@ Return a new empty module object called \var{name}. This object is
\emph
{
not
}
inserted in
\code
{
sys.modules
}
.
\end{funcdesc}
\begin{funcdesc}
{
lock
_
held
}{}
Return 1 if the import lock is currently held, else 0.
On platforms without threads, always return 0.
On platforms with threads, a thread executing an import holds an internal
lock until the import is complete.
This lock blocks other threads from doing an import until the original
import completes, which in turn prevents other threads from seeing
incomplete module objects constructed by the original thread while in
the process of completing its import (and the imports, if any,
triggered by that).
\end{funcdesc}
The following constants with integer values, defined in this module,
are used to indicate the search result of
\function
{
find
_
module()
}
.
...
...
Lib/test/test_threaded_import.py
View file @
69232348
...
...
@@ -32,10 +32,12 @@ def task():
def
test_main
():
# magic name! see above
global
N
,
done
import
sys
for
modname
in
sys
.
modules
:
if
modname
.
find
(
'autotest'
)
>=
0
:
raise
TestSkipped
(
"can't run from autotest"
)
import
imp
if
imp
.
lock_held
():
# This triggers on, e.g., from test import autotest.
raise
TestSkipped
(
"can't run when import lock is held"
)
done
.
acquire
()
for
N
in
(
20
,
50
)
*
3
:
if
verbose
:
...
...
Misc/NEWS
View file @
69232348
...
...
@@ -8,6 +8,9 @@ Core
Library
+ A new function, imp.lock_held(), returns 1 when the import lock is
currently held. See the docs for the imp module.
+ pickle, cPickle and marshal on 32-bit platforms can now correctly read
dumps containing ints written on platforms where Python ints are 8 bytes.
When read on a box where Python ints are 4 bytes, such values are
...
...
@@ -17,6 +20,12 @@ Tools
Build
API
+ XXX Say something about Neil's GC rework, and that extensions that
don't upgrade to the new scheme will still compile but not actually
participate in GC.
New platforms
Tests
...
...
Python/import.c
View file @
69232348
...
...
@@ -181,6 +181,18 @@ unlock_import(void)
#endif
static
PyObject
*
imp_lock_held
(
PyObject
*
self
,
PyObject
*
args
)
{
if
(
!
PyArg_ParseTuple
(
args
,
":lock_held"
))
return
NULL
;
#ifdef WITH_THREAD
return
PyInt_FromLong
(
import_lock_thread
!=
-
1
);
#else
return
PyInt_FromLong
(
0
);
#endif
}
/* Helper for sys */
PyObject
*
...
...
@@ -2339,12 +2351,19 @@ Create a new module. Do not enter it in sys.modules.\n\
The module name must include the full package name, if any.\
"
;
static
char
doc_lock_held
[]
=
"\
lock_held() -> 0 or 1
\n
\
Return 1 if the import lock is currently held.
\n
\
On platforms without threads, return 0.\
"
;
static
PyMethodDef
imp_methods
[]
=
{
{
"find_module"
,
imp_find_module
,
1
,
doc_find_module
},
{
"get_magic"
,
imp_get_magic
,
1
,
doc_get_magic
},
{
"get_suffixes"
,
imp_get_suffixes
,
1
,
doc_get_suffixes
},
{
"load_module"
,
imp_load_module
,
1
,
doc_load_module
},
{
"new_module"
,
imp_new_module
,
1
,
doc_new_module
},
{
"lock_held"
,
imp_lock_held
,
1
,
doc_lock_held
},
/* The rest are obsolete */
{
"get_frozen_object"
,
imp_get_frozen_object
,
1
},
{
"init_builtin"
,
imp_init_builtin
,
1
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment