Note that there are some explanatory texts on larger screens.

plurals
  1. POCherryPy interferes with Twisted shutting down on Windows
    text
    copied!<p>I've got an application that runs Twisted by starting the reactor with <code>reactor.run()</code> in my main thread after starting some other threads, including the CherryPy web server. Here's a program that shuts down cleanly when Ctrl+C is pressed on Linux but not on Windows:</p> <pre><code>from threading import Thread from signal import signal, SIGINT import cherrypy from twisted.internet import reactor from twisted.web.client import getPage def stop(signum, frame): cherrypy.engine.exit() reactor.callFromThread(reactor.stop) signal(SIGINT, stop) class Root: @cherrypy.expose def index(self): reactor.callFromThread(kickoff) return "Hello World!" cherrypy.server.socket_host = "0.0.0.0" Thread(target=cherrypy.quickstart, args=[Root()]).start() def print_page(html): print(html) def kickoff(): getPage("http://acpstats/account/login").addCallback(print_page) reactor.run() </code></pre> <p>I believe that CherryPy is the culprit here, because here's a different program that I wrote without CherryPy that does shutdown cleanly on both Linux and Windows when Ctrl+C is pressed:</p> <pre><code>from time import sleep from threading import Thread from signal import signal, SIGINT from twisted.internet import reactor from twisted.web.client import getPage keep_going = True def stop(signum, frame): global keep_going keep_going = False reactor.callFromThread(reactor.stop) signal(SIGINT, stop) def print_page(html): print(html) def kickoff(): getPage("http://acpstats/account/login").addCallback(print_page) def periodic_downloader(): while keep_going: reactor.callFromThread(kickoff) sleep(5) Thread(target=periodic_downloader).start() reactor.run() </code></pre> <p>Does anyone have any idea what the problem is? Here's my conundrum:</p> <ul> <li>On Linux everything works</li> <li>On Windows, I can call functions from signal handlers using <code>reactor.callFromThread</code> when CherryPy is not running</li> <li>When CherryPy is running, no function that I call using <code>reactor.callFromThread</code> from a signal handler will ever execute (I've verified that the signal handler itself does get called)</li> </ul> <p>What can I do about this? How can I shut down Twisted on Windows from a signal handler while running CherryPy? Is this a bug, or have I simply missed some important part of the documentation for either of these two projects?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload