Shutting down twisted reacotr

  • Thread starter Operation Latte Thunder
  • Start date
O

Operation Latte Thunder

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?
 
J

Jason Mobarak

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()
 
O

Operation Latte Thunder

Jason Mobarak said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top