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

Clark C. Evans cce at clarkevans.com
Wed Nov 16 14:29:28 MST 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

Best,

Clark
-------------- 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))
    s.setServiceParent(application)

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

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



More information about the Twisted-Python mailing list