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 josiahcarlson
Recipients
Date 2006-09-22.20:25:44
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=341410

It's not so much that you can't import in a thread, it's
that you can't import in a thread when the importer is
running in another thread.

When you run a module via 'python module.py', Python
compiles that module into bytecode, then imports the module,
which results in the module being executed.  The execution
of the module performs the various imports, function
definitions, class definitions, etc.  When you start up a
thread while the module is being imported, the import lock
doesn't know what to do and bails out, leaving you with the
situation you are having.

Try rewriting your module like:
import thread
import time
import decimal

def test():
    import decimal
    print "exiting test"

def main():
    thread.start_new_thread(test, ())
    time.sleep(1)

Then running it via:
    python -c "import tmodule;tmodule.main()"

And really, aside from "importing in a thread can be
troublesome, if you don't know what you are doing, don't do
it", what kind of documentation change would you suggest,
and where would it go?
History
Date User Action Args
2008-01-20 09:59:00adminlinkissue1562822 messages
2008-01-20 09:59:00admincreate