[Twisted-Python] twistd -noy unable to cancel using CTRL+C when using threads

Clark C. Evans cce at clarkevans.com
Wed Nov 16 16:29:28 EST 2005

Hello.  The attached example works properly when called from

   twistd -nox test.py

when one is not using threads.  However, as soon as thread are
introduced, you can no longer use CTRL+C to kill the process.  I'm
running FreeBSD 5.3-RELEASE and Python 2.4.1


-------------- next part --------------
from twisted.internet import reactor, defer
from twisted.web2 import server, http, resource, channel

class Toplevel(resource.Resource):
  addSlash = True
  def render(self, ctx):
    return http.Response(stream="Hello monkey!")

# Standard twisted application Boilerplate
from twisted.application import service, strports
application = service.Application("demoserver")

def startup(application):
    site = server.Site(Toplevel())
    s = strports.service('tcp:8080', channel.HTTPFactory(site))

d = defer.Deferred()
d.addCallback(lambda _: startup(application))

if 0:
    # this works properly
    reactor.callLater(1, lambda: d.callback(None))
    # this does not, with or without the init()
    #from twisted.python import threadable
    def block(): 
        import time

More information about the Twisted-Python mailing list