diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-01-21 07:07:30 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-01-21 07:07:30 (GMT) |
commit | 172c40b20add5bb0c8736265ba7fc0033bc65cf7 (patch) | |
tree | 04d9e480a78c70374184e987e80eb73a872a750b /Demo/threads/bug.py | |
parent | dfc538acae7b896058e01571dcf36669e80d8e8b (diff) | |
download | cpython-172c40b20add5bb0c8736265ba7fc0033bc65cf7.zip cpython-172c40b20add5bb0c8736265ba7fc0033bc65cf7.tar.gz cpython-172c40b20add5bb0c8736265ba7fc0033bc65cf7.tar.bz2 |
Whitespace normalization.
Diffstat (limited to 'Demo/threads/bug.py')
-rw-r--r-- | Demo/threads/bug.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Demo/threads/bug.py b/Demo/threads/bug.py index 5860536..6c5edac 100644 --- a/Demo/threads/bug.py +++ b/Demo/threads/bug.py @@ -1,12 +1,12 @@ # The following self-contained little program usually freezes with most # threads reporting -# +# # Unhandled exception in thread: # Traceback (innermost last): # File "importbug.py", line 6 # x = whrandom.randint(1,3) # AttributeError: randint -# +# # Here's the program; it doesn't use anything from the attached module: import thread @@ -33,37 +33,37 @@ print 'done' # Sticking an acquire/release pair around the 'import' statement makes the # problem go away. -# +# # I believe that what happens is: -# +# # 1) The first thread to hit the import atomically reaches, and executes # most of, get_module. In particular, it finds Lib/whrandom.pyc, # installs its name in sys.modules, and executes -# +# # v = eval_code(co, d, d, d, (object *)NULL); -# +# # to initialize the module. -# +# # 2) eval_code "ticker"-slices the 1st thread out, and gives another thread # a chance. When this 2nd thread hits the same 'import', import_module # finds 'whrandom' in sys.modules, so just proceeds. -# +# # 3) But the 1st thread is still "in the middle" of executing whrandom.pyc. # So the 2nd thread has a good chance of trying to look up 'randint' # before the 1st thread has placed it in whrandom's dict. -# +# # 4) The more threads there are, the more likely that at least one of them # will do this before the 1st thread finishes the import work. -# +# # If that's right, a perhaps not-too-bad workaround would be to introduce a # static "you can't interrupt this thread" flag in ceval.c, check it before # giving up interpreter_lock, and have IMPORT_NAME set it & restore (plain # clearing would not work) it around its call to import_module. To its # credit, there's something wonderfully perverse about fixing a race via an # unprotected static <grin>. -# +# # as-with-most-other-things-(pseudo-)parallel-programming's-more-fun- # in-python-too!-ly y'rs - tim -# +# # Tim Peters tim@ksr.com # not speaking for Kendall Square Research Corp |