def stop_reactor():
 global _twisted_thread
 def _stop_reactor():
  '"Helper for calling stop from withing the thread.'
  reactor.stop()
 reactor.callFromThread(_stop_reactor)
 reactor_thread.join()
 for p in reactor.getDelayedCalls():
  if p.active():
   p.cancel()
 _twisted_thread = None

def stop_reactor ( ) : global _twisted_thread def _stop_reactor ( ) : reactor . stop ( ) reactor . callFromThread ( _stop_reactor ) reactor_thread . join ( ) for p in reactor . getDelayedCalls ( ) : if p . active ( ) : p . cancel ( ) _twisted_thread = None
stop the reactor and join the reactor thread until it stops .