from multiprocessing import Process
a=Process(target=worker, args=())
a.start()
I am making a multiple worker-process app (don’t laugh yet) in which each worker can gracefully reload. Whenever the code is updated, new requests are served by new worker processes with the new code. This is such that
- A newly launched thread contains updated code
- ensure that no requests are dropped
I already made a worker that listens:
- serves requests when it gets aa request signal
- kills itself when the next signal is a control signal
I did it in zeromq. The clients connect to this server using zeromq. The clients do not interact by HTTP.
What is a good way to reload the code? Can you explain a scheme that is simple and stupid enough to be robust?
What I have in mind/ can do
Launch a thread within the main process that iterates:
- Signal every worker process to die
- Launch new worker processes
But this approach will drop (I configured it that way) requests between the death of the last old worker and the spawning of the first new worker.
And no, I am not a college student. The "homework" just means a curiosity-driven pursuit.
Reloading code in python is a notoriously difficult problem.
Here’s how I would deal with it:
acceptconnections and service requests.socket.errorexception, and should terminatesubprocess.Popen(sys.argv)) the new process can start accepting connections immediately.