-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows: multiprocessing causes KeyError: '__mp_main__' #79
Comments
To repeat, this is the script and logging result that @rahulraj80 obtained with solution applied: The entire contents of the runner Script: # Tractor_Training_runner.py
import tractor
import multiprocessing
#from . import TractorTraining
import os
os.chdir(r"c:/users/rahul/source/repos/TwistedTraining/TwistedTraining/TwistedTraining")
import TractorTraining
if __name__ == '__main__':
multiprocessing.freeze_support()
tractor.run(TractorTraining.main) Log:
The cancellation reporting at the end is expected with the "warn" level logging enabled. I'm not sure if all of these messages should be "warn" level since a lot of them are expected during graceful teardown. An example where "info" level might be better is here. |
Thanks to @salotz for pointing out that the first example in the docs was broken. Though it's somewhat embarrassing this might also explain the problem in #79 and certain issues in #59... The solution here is to import the target RPC module using the its unique basename and absolute filepath in the sub-actor that requires it. Special handling for `__main__` and `__mp_main__` is needed since the spawned subprocess will have no knowledge about these parent- -state-specific module variables. Solution: map the modules name to the respective module file basename in the child process since the module variables will of course have different values in children.
Thanks to @salotz for pointing out that the first example in the docs was broken. Though it's somewhat embarrassing this might also explain the problem in #79 and certain issues in #59... The solution here is to import the target RPC module using the its unique basename and absolute filepath in the sub-actor that requires it. Special handling for `__main__` and `__mp_main__` is needed since the spawned subprocess will have no knowledge about these parent- -state-specific module variables. Solution: map the modules name to the respective module file basename in the child process since the module variables will of course have different values in children.
Thanks to @salotz for pointing out that the first example in the docs was broken. Though it's somewhat embarrassing this might also explain the problem in #79 and certain issues in #59... The solution here is to import the target RPC module using the its unique basename and absolute filepath in the sub-actor that requires it. Special handling for `__main__` and `__mp_main__` is needed since the spawned subprocess will have no knowledge about these parent- -state-specific module variables. Solution: map the modules name to the respective module file basename in the child process since the module variables will of course have different values in children.
This is an issue that can show up on windows without special construction of a
__main__
script in a python program usingtractor
.When running the first example in a script the traceback log will look something like the following output:
Click to show log
The issue was first described by @chrizzFTD in #61. @rahulraj80 also experienced this but was able to use @chrizzFTD's solution to get a similar working result. This solution is based on this SO question.
We need to document this solution under the windows gotchas in the readme such that it's available for easy reference.
The text was updated successfully, but these errors were encountered: