[zeromq-dev] python, calls not unblocking on signal
Hi, I'm running workers in different threads of a python app, while the main thread sleeps. I want to be able to cleanly shutdown the app when ctrl-c is pressed. As it is now, when ctrl-c is pressed, the main thread receives KeyboardException. However, blocking zmq calls in the worker threads do not return with EINTR and so all the threads remain stuck. Is this a python peculiarity regarding signal handling? How are people doing clean shutdowns on ctrl-c with python? Thanks, Justin ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] python, calls not unblocking on signal
On Wed, Feb 1, 2012 at 10:02, Justin Karneges jus...@affinix.com wrote: Hi, I'm running workers in different threads of a python app, while the main thread sleeps. I want to be able to cleanly shutdown the app when ctrl-c is pressed. As it is now, when ctrl-c is pressed, the main thread receives KeyboardException. However, blocking zmq calls in the worker threads do not return with EINTR and so all the threads remain stuck. Is this a python peculiarity regarding signal handling? How are people doing clean shutdowns on ctrl-c with python? It's a general Python issue. Python + Threads + Signals = mess. From the signal doc http://docs.python.org/library/signal.html: only the main thread can set a new signal handler, and the main thread will be the only one to receive signals (this is enforced by the Python signal module, even if the underlying thread implementation supports sending signals to individual threads) -MinRK Thanks, Justin ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] python, calls not unblocking on signal
On Wednesday, February 01, 2012 10:15:10 AM MinRK wrote: Is this a python peculiarity regarding signal handling? How are people doing clean shutdowns on ctrl-c with python? It's a general Python issue. Python + Threads + Signals = mess. From the signal doc http://docs.python.org/library/signal.html: only the main thread can set a new signal handler, and the main thread will be the only one to receive signals (this is enforced by the Python signal module, even if the underlying thread implementation supports sending signals to individual threads) Bummer. Poller and non-blocking writes it is, I guess... Justin ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] python, calls not unblocking on signal
On Wed, Feb 1, 2012 at 11:01, Justin Karneges jus...@affinix.com wrote: On Wednesday, February 01, 2012 10:15:10 AM MinRK wrote: Is this a python peculiarity regarding signal handling? How are people doing clean shutdowns on ctrl-c with python? It's a general Python issue. Python + Threads + Signals = mess. From the signal doc http://docs.python.org/library/signal.html: only the main thread can set a new signal handler, and the main thread will be the only one to receive signals (this is enforced by the Python signal module, even if the underlying thread implementation supports sending signals to individual threads) Bummer. Poller and non-blocking writes it is, I guess... If you are just looking for clean shutdown, you can terminate the Context from the main thread when it is interrupted, and then blocking calls in other threads will raise ZMQError(ETERM). For example: https://gist.github.com/1720387 -MinRK ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] python, calls not unblocking on signal
On Wednesday, February 01, 2012 04:31:35 PM MinRK wrote: If you are just looking for clean shutdown, you can terminate the Context from the main thread when it is interrupted, and then blocking calls in other threads will raise ZMQError(ETERM). For example: https://gist.github.com/1720387 Thanks! I see ETERM is actually a standard feature of libzmq, very nice. ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev