-
Notifications
You must be signed in to change notification settings - Fork 712
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
Fix removing simple queue in child processes #325
Conversation
Wow! Thanks a lot for taking the time to investigate and fix this issue! Kudos for finding the solution. To be honest I'm still scratching my head trying to figure out what's going on. 😲
Why that? It will take me probably some time to properly grasp all of that, but I will publish your correction as soon as possible. Thank you very much! |
I will try to describe it :) And I want to apologize because last part "Another way how to fix it..." of my previous comment is not correct. 1), 2) Why does calling multiprocessing.current_process() in the child returns the same process as in the parent? and 3b) Why does it fail if _owner_process is a Process() object but not if it's an int?Why multiprocessing returns the same object? Because of this and this. This object/instance is created once in master process and everytime when you call I can show you my custom output from code (everywhere is the same object but it behaves differently):
3a) Is uwsgi somehow mutating the main process?The 4) Why does it freeze at stop() anyway?This condition means children should return and don't continue in code. But every child thinks he is master so every child kills logging thread (simple queue) and I don't know exactly why but it causes timeout in children/worker proccesses. |
Thanks for the explanations! One thing is still confusing me.
That's not what I'm observing while using standard import multiprocessing
main = multiprocessing.current_process()
def hello_world():
child = multiprocessing.current_process()
print("main == child:", main == child)
if __name__ == "__main__":
p = multiprocessing.Process(target=hello_world)
p.start()
p.join() This prints Using import multiprocessing
from flask import Flask
application = Flask(__name__)
main = multiprocessing.current_process()
@application.route('/')
def hello_world():
child = multiprocessing.current_process()
return "main == child: {}".format(main == child) That's this behavior difference that I can't understand. 😕 |
Hmm.. I checked multiprocessing code and I see reason probably there. This library does some overhead before starting process. I see it calls I'm not sure but |
Yeah, Anyway, thanks again. I wanted to be sure it was somehow related to I will merge this PR and probably publish a new version during the week-end. 👍 |
I am glad I could help you :) |
Again, thanks a lot for your help! It should be fine in |
Hello, I think this pull request could fix #309.
There is problem with calling
multiprocessing.current_process()
which returns the instance of_MainProcess()
. But because this code is executed before a new thread there are same values/objects. In child process is the same object as in parent process. You can check it withid(self._owner_process)
.Source code of multiprocessing: https://github.com/python/cpython/blob/master/Lib/multiprocessing/process.py#L41
Another way how to fix it is to move
self._owner_process = multiprocessing.current_process()
after creating a new thread. There would be different objects in every process. But I think there is better to work wih PID numbers than objects.