Пример #1
0
 def processEnded(self, status_object):
     if self.shutdown_trigger:
         reactor.removeSystemEventTrigger(self.shutdown_trigger)
         self.shutdown_trigger = None
     self.deferred.callback(status_object.value.exitCode)
     for d in self.shutdown_deferreds:
         d.callback(status_object.value.exitCode)
Пример #2
0
 def removeTrigger(self, trigger):
     """
     Remove a trigger by its handle from the reactor and from
     C{self.triggers}.
     """
     reactor.removeSystemEventTrigger(trigger)
     self.triggers.remove(trigger)
Пример #3
0
    def run(self):
        while (self._current_connect_attempts_count <
               self._MAX_CONNECT_ATTEMPTS and not self._stopping):
            self.connection = None
            self._deliveries = []
            self._acked = 0
            self._nacked = 0
            self._message_number = 0

            self.connection = self.connect()

            if self.shutdown_event_handler is not None:
                try:
                    reactor.removeSystemEventTrigger(
                        self.shutdown_event_handler)
                except (KeyError, ValueError, TypeError):
                    pass
                self.shutdown_event_handler = None
            if reactor.running:
                cb = functools.partial(
                    self.connection.ioloop.add_callback_threadsafe,
                    self.stop_from_reactor_event)
                self.shutdown_event_handler = reactor.addSystemEventTrigger(
                    "before", "shutdown", cb)

            self.connection.ioloop.start()
        logger.info("Stopped")
Пример #4
0
 def shutdown(self):
     """Shutdown the worker thread.
     """
     self._q.put(self.SHUTDOWN)
     if self._shutdownTriggerId is not None:
         reactor.removeSystemEventTrigger(self._shutdownTriggerId)
         self._shutdownTriggerId = None
Пример #5
0
 def processEnded(self, status_object):
     if self.shutdown_trigger:
         reactor.removeSystemEventTrigger(self.shutdown_trigger)
         self.shutdown_trigger = None
     self.deferred.callback(status_object.value.exitCode)
     for d in self.shutdown_deferreds:
         d.callback(status_object.value.exitCode)
Пример #6
0
 def removeTrigger(self, trigger):
     """
     Remove a trigger by its handle from the reactor and from
     C{self.triggers}.
     """
     reactor.removeSystemEventTrigger(trigger)
     self.triggers.remove(trigger)
Пример #7
0
 def shutdown(self):
     """
     Cleanly shuts me down.
     """
     if self.triggerID is None: return
     reactor.removeSystemEventTrigger(self.triggerID)
     self.triggerID = None
     self.transport.loseConnection()
Пример #8
0
 def shutdown(self):
     self.shutting_down = True
     try:
         reactor.removeSystemEventTrigger(self.shutdown_trigger)
     except ValueError:
         pass # We may have been called automatically at shutdown.
     if self.proc:
         self.proc.signalProcess("INT")
Пример #9
0
 def shutdown(self):
     """Manually stop the pool.  This is only necessary from tests, as the
     pool will stop itself when the reactor stops under normal
     circumstances."""
     if not self._stop_evt:
         return  # pool is already stopped
     reactor.removeSystemEventTrigger(self._stop_evt)
     self._stop()
Пример #10
0
 def shutdown(self):
     """Manually stop the pool.  This is only necessary from tests, as the
     pool will stop itself when the reactor stops under normal
     circumstances."""
     if not self._stop_evt:
         return # pool is already stopped
     reactor.removeSystemEventTrigger(self._stop_evt)
     self._stop()
Пример #11
0
 def shutdown(self):
     self.shutting_down = True
     try:
         reactor.removeSystemEventTrigger(self.shutdown_trigger)
     except ValueError:
         pass  # We may have been called automatically at shutdown.
     if self.proc:
         self.proc.signalProcess("INT")
Пример #12
0
 def clean_up(failure):
     if self.missing_timer is not None:
         self.missing_timer.cancel()
         self._substantiation_failed(failure)
     if self._shutdown_callback_handle is not None:
         handle = self._shutdown_callback_handle
         del self._shutdown_callback_handle
         reactor.removeSystemEventTrigger(handle)
     return failure
Пример #13
0
    def stop(self):
        """stop()

        Stop all services in the region's event-loop.
        """
        if self.handle is not None:
            handle, self.handle = self.handle, None
            reactor.removeSystemEventTrigger(handle)
        return self.services.stopService()
Пример #14
0
 def clean_up(failure):
     if self.missing_timer is not None:
         self.missing_timer.cancel()
         self._substantiation_failed(failure)
     if self._shutdown_callback_handle is not None:
         handle = self._shutdown_callback_handle
         del self._shutdown_callback_handle
         reactor.removeSystemEventTrigger(handle)
     return failure
Пример #15
0
 def close(self):
     """Close all pool connections and shutdown the pool"""
     if self.shutdownID:
         reactor.removeSystemEventTrigger(self.shutdownID)
         self.shutdownID = None
     if self.startID:
         reactor.removeSystemEventTrigger(self.startID)
         self.startID = None
     self.finalClose()
Пример #16
0
 def close(self):
     """Close all pool connections and shutdown the pool."""
     from twisted.internet import reactor
     if self.shutdownID:
         reactor.removeSystemEventTrigger(self.shutdownID)
         self.shutdownID = None
     if self.startID:
         reactor.removeSystemEventTrigger(self.startID)
         self.startID = None
     self.finalClose()
Пример #17
0
 def tearDown(self):
     """
     Remove all remaining triggers from the reactor.
     """
     while self.triggers:
         trigger = self.triggers.pop()
         try:
             reactor.removeSystemEventTrigger(trigger)
         except (ValueError, KeyError):
             pass
Пример #18
0
 def tearDown(self):
     """
     Remove all remaining triggers from the reactor.
     """
     while self.triggers:
         trigger = self.triggers.pop()
         try:
             reactor.removeSystemEventTrigger(trigger)
         except (ValueError, KeyError):
             pass
Пример #19
0
 def insubstantiate(self, fast=False):
     self._clearBuildWaitTimer()
     d = self.stop_instance(fast)
     if self._shutdown_callback_handle is not None:
         handle = self._shutdown_callback_handle
         del self._shutdown_callback_handle
         reactor.removeSystemEventTrigger(handle)
     self.substantiated = False
     self.building.clear()  # just to be sure
     return d
Пример #20
0
 def insubstantiate(self, fast=False):
     self._clearBuildWaitTimer()
     d = self.stop_instance(fast)
     if self._shutdown_callback_handle is not None:
         handle = self._shutdown_callback_handle
         del self._shutdown_callback_handle
         reactor.removeSystemEventTrigger(handle)
     self.substantiated = False
     self.building.clear() # just to be sure
     return d
Пример #21
0
 def shutdown(self):
     if self.triggerID is not None:
         reactor.removeSystemEventTrigger(self.triggerID)
         self.triggerID = None
         yield self.done()
         if hasattr(self, 'tempDir'):
             try:
                 shutil.rmtree(self.tempDir)
             except:
                 pass
             del self.tempDir
Пример #22
0
    def close(self):
        """Close all pool connections and shutdown the pool."""

        from twisted.internet import reactor
        if self.shutdownID:
            reactor.removeSystemEventTrigger(self.shutdownID)
            self.shutdownID = None
        if self.startID:
            reactor.removeSystemEventTrigger(self.startID)
            self.startID = None
        self.finalClose()
Пример #23
0
	def __init__(self, dbapiName, *connargs, **connkw):
		"""
		Create a new instance of the connection pool.
		
		This overridden constructor makes sure the Twisted reactor
		doesn't get started in non-twisted.web-hosted environments.
		"""
		TimeoutConnectionPool.__init__(self, dbapiName, *connargs, **connkw)
		from twisted.internet import reactor
		if(self.startID):
			reactor.removeSystemEventTrigger(self.startID)
Пример #24
0
    def stop(self):
        log.msg("IRCBotPlugin stopping...")
        if self.shutdown_trigger is not None:
            reactor.removeSystemEventTrigger(self.shutdown_trigger)
        self.stopTrying()
        if self.client:
            log.msg("Sending quit message")
            self.client.quit("Daisy, daisy...")

        # The server should disconnect us after a QUIT command, but just in
        # case, terminate the connection after 5 seconds.
        reactor.callLater(5, self.connector.disconnect)
Пример #25
0
    def stop(self):
        log.msg("IRCBotPlugin stopping...")
        if self.shutdown_trigger is not None:
            reactor.removeSystemEventTrigger(self.shutdown_trigger)
        self.stopTrying()
        if self.client:
            log.msg("Sending quit message")
            self.client.quit("Daisy, daisy...")

        # The server should disconnect us after a QUIT command, but just in
        # case, terminate the connection after 5 seconds.
        reactor.callLater(5, self.connector.disconnect)
Пример #26
0
 def _cleanThreads(self):
     reactor = self._getReactor()
     if interfaces.IReactorThreads.providedBy(reactor):
         reactor.suggestThreadPoolSize(0)
         if getattr(reactor, "threadpool", None) is not None:
             try:
                 reactor.removeSystemEventTrigger(reactor.threadpoolShutdownID)
             except KeyError:
                 pass
             # Remove the threadpool, and let the reactor put it back again
             # later like a good boy
             reactor._stopThreadPool()
Пример #27
0
    def __init__(self, dbapiName, *connargs, **connkw):
        """
		Create a new instance of the connection pool.
		
		This overridden constructor makes sure the Twisted reactor
		doesn't get started in non-twisted.web-hosted environments.
		"""
        TimeoutConnectionPool.__init__(self, dbapiName, *connargs, **connkw)
        from twisted.internet import reactor
        if (self.startID):
            reactor.removeSystemEventTrigger(self.startID)
            self.startID = None
Пример #28
0
 def shutdown(self):
     if hasattr(self, 'triggerID'):
         reactor.removeSystemEventTrigger(self.triggerID)
         del self.triggerID
     if hasattr(self, 'runner'):
         dList = []
         for ri in self.pendingRuns.itervalues():
             dList.append(ri.dRun)
             if not ri.dCancel.called:
                 ri.dCancel.callback(None)
         yield defer.DeferredList(dList)
         yield self.runner.q.shutdown()
Пример #29
0
    def shutdown(self):
        """
        There is only one appropriate callback for shutting the program
        down, and this is it. Let the reactor call it automatically
        when you do a reactor.stop().
        """
        def done(null):
            reactor.stop()

        if hasattr(self, 'triggerID'):
            reactor.removeSystemEventTrigger(self.triggerID)
            del self.triggerID
        return self.reader.shutdown().addCallbacks(done, oops)
Пример #30
0
 def insubstantiate(self, fast=False):
     self.insubstantiating = True
     self._clearBuildWaitTimer()
     d = self.stop_instance(fast)
     if self._shutdown_callback_handle is not None:
         handle = self._shutdown_callback_handle
         del self._shutdown_callback_handle
         reactor.removeSystemEventTrigger(handle)
     self.substantiated = False
     self.building.clear()  # just to be sure
     yield d
     self.insubstantiating = False
     self.botmaster.maybeStartBuildsForSlave(self.name)
Пример #31
0
 def insubstantiate(self, fast=False):
     self.insubstantiating = True
     self._clearBuildWaitTimer()
     d = self.stop_instance(fast)
     if self._shutdown_callback_handle is not None:
         handle = self._shutdown_callback_handle
         del self._shutdown_callback_handle
         reactor.removeSystemEventTrigger(handle)
     self.substantiated = False
     self.building.clear()  # just to be sure
     yield d
     self.insubstantiating = False
     self.botmaster.maybeStartBuildsForWorker(self.name)
Пример #32
0
 def unmapRTP(self):
     from xshtoom.nat import getMapper
     if self.needSTUN is False:
         return defer.succeed(None)
     # Currently removing an already-fired trigger doesn't hurt,
     # but this seems likely to change.
     try:
         reactor.removeSystemEventTrigger(self._shutdownHook)
     except:
         pass
     d = getMapper()
     d.addCallback(self._cb_unmap_gotMapper)
     return d
Пример #33
0
 def _cleanThreads(self):
     reactor = self._getReactor()
     if interfaces.IReactorThreads.providedBy(reactor):
         reactor.suggestThreadPoolSize(0)
         if getattr(reactor, 'threadpool', None) is not None:
             try:
                 reactor.removeSystemEventTrigger(
                     reactor.threadpoolShutdownID)
             except KeyError:
                 pass
             # Remove the threadpool, and let the reactor put it back again
             # later like a good boy
             reactor._stopThreadPool()
Пример #34
0
 def unmapRTP(self):
     from shtoom.nat import getMapper
     if self.needSTUN is False:
         return defer.succeed(None)
     # Currently removing an already-fired trigger doesn't hurt,
     # but this seems likely to change.
     try:
         reactor.removeSystemEventTrigger(self._shutdownHook)
     except:
         pass
     d = getMapper()
     d.addCallback(self._cb_unmap_gotMapper)
     return d
Пример #35
0
 def _stopServer(self, *ignored):
     self.stopping = True
     try:
         yield self._dispatch(self.stopServer)
     except Exception as e:
         self._error = failure.Failure(e)
     finally:
         try:
             self._cxn.disconnect()
         except Exception:
             pass
         # remove the event trigger, so we don't get
         # called again if the reactor shuts down later
         if hasattr(self, '_shutdownID'):
             reactor.removeSystemEventTrigger(self._shutdownID)
Пример #36
0
 def _stopServer(self, *ignored):
     self.stopping = True
     try:
         yield self._dispatch(self.stopServer)
     except Exception as e:
         self._error = failure.Failure(e)
     finally:
         try:
             self._cxn.disconnect()
         except Exception:
             pass
         # remove the event trigger, so we don't get
         # called again if the reactor shuts down later
         if hasattr(self, '_shutdownID'):
             reactor.removeSystemEventTrigger(self._shutdownID)
Пример #37
0
 def shutdown( self ):
     
     logger.debug( "Cleaning up before shutdown." )
     
     if self.shutdown_trigger_id is not None:        
         reactor.removeSystemEventTrigger( self.shutdown_trigger_id )
     
     deferreds = []
     
     if self.site is not None:
         logger.debug( "Stopping listening on main HTTP interface." )
         d = self.site_port.stopListening()
         if isinstance(d, Deferred):
             deferreds.append( d )
     
     if self.web_admin_site is not None:
         logger.debug( "Stopping listening on web admin interface." )
         d = self.web_admin_site_port.stopListening()
         if isinstance(d, Deferred):
             deferreds.append( d )
             
     if self.coordinateloop is not None:
         logger.debug( "Stopping coordinating loop." )
         d = self.coordinateloop.stop()
         if isinstance(d, Deferred):
             deferreds.append( d )
             
     if self.queryloop is not None:
         logger.debug( "Stopping query loop." )
         d = self.queryloop.stop()
         if isinstance(d, Deferred):
             deferreds.append( d )
             
     if self.aws_sdb_coordination_domain is not None:
         logger.debug( "Removing data from SDB coordination domain." )
         d = self.sdb.delete( self.aws_sdb_coordination_domain, self.uuid )
         d.addCallback(self._cleanupBeforeShutdown)
         d.addCallback(self.peerCheckRequest)
         deferreds.append( d )
     
     if len( deferreds ) > 0:
         logger.debug( "Combinining deferred shutdown processes." )
         d = DeferredList( deferreds )
         d.addCallback( self._shutdownCallback )
         return d
     else:
         logger.debug( "No deferred processes." )
         return self._shutdownCallback( None )
Пример #38
0
 def stop(self):
     if self.shutdown_event_handler is not None:
         try:
             reactor.removeSystemEventTrigger(self.shutdown_event_handler)
         except (KeyError, ValueError, TypeError):
             pass
         self.shutdown_event_handler = None
     self._current_connect_attempts_count = 0
     self._current_graceful_stop_attempts_count = 0
     self.can_interact = False
     self.__owner_update_can_interact_value()
     if self.is_consumer:
         self._stop_as_consumer()
     else:
         self._stop_default()
     if not self._stopping:
         logger.info("Stopping In Progress")
Пример #39
0
    def shutdown(self):
        """
        This gets called before the reactor shuts down. Causes any pending
        delays or L{untilEvent} calls to finish up pronto.

        Does not return a C{Deferred}, because it doesn't return until
        it's forced everything to wind up.
        """
        if self.triggerID is None:
            return
        reactor.removeSystemEventTrigger(self.triggerID)
        self.triggerID = None
        while self.pendingCalls:
            call = self.pendingCalls.keys()[0]
            if call.active():
                self.pendingCalls[call].callback(None)
                call.cancel()
Пример #40
0
 def cleanup(self):
     """
     Cleans up the reactor stuff.
     @rtype: L{twisted.defer.DeferredList}
     """
     log.info("_cleanup the Master")
     deferreds = []
     reactor.removeSystemEventTrigger(self._shutdown_event_id)
     # quit all slaves
     for command in self.get_all_commands():
         if command.slave_state == STATE_RUNNING:
             deferreds.append(command.quit_slave())
     # stop the master's loop
     if self._looping_call.running:
         d = self._looping_call.deferred
         self._looping_call.stop() # FIXME
         deferreds.append(d)
     return defer.DeferredList(deferreds)
Пример #41
0
    def shutdown(self):
        """
        Call this to shut me down gracefully.

        Repeated calls are ignored. Gets called when the Enter key is
        pressed.
        
        Sets my I{running} flag C{False}, which lets all my various
        loops know that it's time to quit early. Calls
        L{Population.abort} on my L{Population} object I{p} to shut it
        down ASAP.
        """
        if self.triggerID:
            reactor.removeSystemEventTrigger(self.triggerID)
            self.triggerID = None
        if self.running:
            self.running = False
            msg(0, "Shutting down DE...")
            if self.dChallenges and not self.dChallenges.called:
                self.dChallenges.errback(abort.AbortError())
Пример #42
0
 def do_timer():
     reactor.removeSystemEventTrigger(calls['shutdown'])
     do_cmd()
Пример #43
0
 def _cancelCleanup(self, result, call_id):
     reactor.removeSystemEventTrigger(call_id)
     return result
Пример #44
0
 def shutdown(self):
     """End the pending webclient calls."""
     self.running = False
     # pylint: disable=E1101
     reactor.removeSystemEventTrigger(self.trigger_id)
Пример #45
0
 def cleanup(result):
     self._destroy_agentproxy()
     reactor.removeSystemEventTrigger(shutdown_trigger_id)
     return result
Пример #46
0
 def _cleanup(res=None):
     sm.loseConnections()
     reactor.removeSystemEventTrigger(smTrigId)
Пример #47
0
 def cleanup(unfinishedTasks):
     if hasattr(self, '_triggerID'):
         reactor.removeSystemEventTrigger(self._triggerID)
         del self._triggerID
     return unfinishedTasks
Пример #48
0
 def tearDown(self):
     for t in self.triggers:
         try:
             reactor.removeSystemEventTrigger(t)
         except:
             pass
Пример #49
0
 def removeTrigger(self, trigger):
     reactor.removeSystemEventTrigger(trigger)
     self.triggers.remove(trigger)
Пример #50
0
 def cleanup(result):
     if hasattr(self, '_triggerID'):
         reactor.removeSystemEventTrigger(self._triggerID)
         del self._triggerID
     self._thread.join()
     return result
Пример #51
0
 def close(self):
     from twisted.internet import reactor
     reactor.removeSystemEventTrigger(self.shutdownID)
     self.finalClose()
Пример #52
0
 def cleanup(result):
     self._destroy_agentproxy()
     reactor.removeSystemEventTrigger(shutdown_trigger_id)
     return result
Пример #53
0
 def tearDown(self):
     for t in self.triggers:
         try:
             reactor.removeSystemEventTrigger(t)
         except:
             pass
Пример #54
0
 def removeTrigger(self, trigger):
     reactor.removeSystemEventTrigger(trigger)
     self.triggers.remove(trigger)
Пример #55
0
 def __del__(self):
     logging.debug("Removing old shutdown event trigger")
     reactor.removeSystemEventTrigger(self._triggerid)
Пример #56
0
 def _cleanup(res=None):
     sm.loseConnections()
     reactor.removeSystemEventTrigger(smTrigId)
Пример #57
0
 def cancel_call_on_shutdown(self, call):
     return reactor.removeSystemEventTrigger(call)
Пример #58
0
 def _cleanup(what):
     if self.shutdownDeferred:
         self.shutdownDeferred.callback(None)
     reactor.removeSystemEventTrigger(triggerID)
     
     return what