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.

Author ncoghlan
Recipients andyshorts, christian.heimes, georg.brandl, ncoghlan, ocean-city
Date 2008-02-25.22:47:34
SpamBayes Score 0.012821175
Marked as misclassified No
Message-id <1203979656.75.0.932334697998.issue1720705@psf.upfronthosting.co.za>
In-reply-to
Content
Proposed wording for a warning pointing that threads and imports can get
you in trouble. It might be better to squirrel off into a new subsection
on threaded imports, rather than giving it too much prominence (since
the recommended approach to creating subthreads should 'just work' -
it's only daemon threads and using the thread module directly that can
get you in trouble):

"""While the import machinery is thread safe, there are two key
restrictions on threaded imports due to inherent limitations in the way
that thread safety is provided.
Firstly, other than in the main module, an import should not have the
side effect of spawning a new thread and then waiting for that thread in
any way. Failing to abide by this restriction can lead to a deadlock if
the spawned thread directly or indirectly attempts to import a module.
Secondly, all import attempts must be completed before the interpreter
starts shutting itself down. This can be most easily achieved by only
performing imports from non-daemon threads created through the threading
module. Daemon threads and threads created directly with the thread
module will require some other form of synchronization to ensure they do
not attempt imports after system shutdown has commenced. Failure to
abide by this restriction will lead to intermittent exceptions and
crashes during interpreter shutdown (as the late imports attempt to
access machinery which is no longer in a valid state)."""

(If we were going to actually change anything in the code, it would be
to ensure that breaking the second restriction could only lead to
exceptions rather than crashes - I suspect that would be pretty messy
though, as there are a bunch of PyImport_* calls that currently can't
fail that would start having to be checked for error returns)
History
Date User Action Args
2008-02-25 22:47:37ncoghlansetspambayes_score: 0.0128212 -> 0.012821175
recipients: + ncoghlan, georg.brandl, ocean-city, andyshorts, christian.heimes
2008-02-25 22:47:36ncoghlansetspambayes_score: 0.0128212 -> 0.0128212
messageid: <1203979656.75.0.932334697998.issue1720705@psf.upfronthosting.co.za>
2008-02-25 22:47:35ncoghlanlinkissue1720705 messages
2008-02-25 22:47:34ncoghlancreate