469,600 Members | 2,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

Shutting down twisted reacotr

I have a simple ( I hope ) problem that I have been baning my head against
all day. I have isolated it down to a very small demo script, which I
will include below.

Basically, I want to have twisted run until an event makes it stop. My
problem is that my reactor.stop() doesn't seem to do anything if its not
called via a calllater or an equivilent. Unfortunately, my google-fu
seems weak today, as I have not been able to discern its solution.
Without further adieu:

from thread import start_new_thread
import time
from twisted.internet import reactor

def shutdown():
time.sleep( 1 )
print "Stopping"
reactor.stop()

start_new_thread ( shutdown, () )

reactor.run()
print "done"

This will continue to run even after printing "Stopping"

any ideas?

--
ch***@acheris.net | Roma Invicta!
Jul 19 '05 #1
3 1908
Why do you want to do this in a thread? What's wrong with
reactor.callLater?

import time
from twisted.internet import reactor

def shutdown():

time.sleep(3)
print "stopping"
reactor.callFromThread(reactor.stop)

reactor.callInThread(shutdown)
reactor.run()

Jul 19 '05 #2
Jason Mobarak <ja***********@gmail.com> wrote:
Why do you want to do this in a thread? What's wrong with
reactor.callLater?

import time
from twisted.internet import reactor

def shutdown():

time.sleep(3)
print "stopping"
reactor.callFromThread(reactor.stop)

reactor.callInThread(shutdown)
reactor.run()


In the app I am playing with, I have a thread that reads from the console.
When it terminates, I wanted it to shut down the reactor and couldn't use
callLater. However, callFromThread worked perfectly. I guess I need to
look at the docs some more to understand why its necessary

--
ch***@acheris.net | Roma Invicta!
Jul 19 '05 #3
You might not need threads to get user input from the console. Jp
posted this in response to a similar query on the twisted-python
mailing list:

http://article.gmane.org/gmane.comp.python.twisted/9019

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Jesper | last post: by
1 post views Thread by mikelostcause | last post: by
4 posts views Thread by Larry Bud | last post: by
2 posts views Thread by =?Utf-8?B?UGF1bA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.