Message61004
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? |
|
Date |
User |
Action |
Args |
2008-01-20 09:59:00 | admin | link | issue1562822 messages |
2008-01-20 09:59:00 | admin | create | |
|