def _handleSigchld(self, signum, frame, _threadSupport=platform.supportsThreads()): """ Reap all processes on SIGCHLD. This gets called on SIGCHLD. We do no processing inside a signal handler, as the calls we make here could occur between any two python bytecode instructions. Deferring processing to the next eventloop round prevents us from violating the state constraints of arbitrary classes. """ from include.twisted.internet.process import reapAllProcesses if _threadSupport: self.callFromThread(reapAllProcesses) else: self.callLater(0, reapAllProcesses)
def __init__(self): self.threadCallQueue = [] self._eventTriggers = {} self._pendingTimedCalls = [] self._newTimedCalls = [] self._cancellations = 0 self.running = False self._started = False self._justStopped = False self.waker = None # Arrange for the running attribute to change to True at the right time # and let a subclass possibly do other things at that time (eg install # signal handlers). self.addSystemEventTrigger( 'during', 'startup', self._reallyStartRunning) self.addSystemEventTrigger('during', 'shutdown', self.crash) self.addSystemEventTrigger('during', 'shutdown', self.disconnectAll) if platform.supportsThreads(): self._initThreads()
""" See L{twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize}. """ if size == 0 and self.threadpool is None: return if self.threadpool is None: self._initThreadPool() self.threadpool.adjustPoolsize(maxthreads=size) else: # This is for signal handlers. def callFromThread(self, f, *args, **kw): assert callable(f), "%s is not callable" % (f,) # See comment in the other callFromThread implementation. self.threadCallQueue.append((f, args, kw)) if platform.supportsThreads(): classImplements(ReactorBase, IReactorThreads) class BaseConnector(styles.Ephemeral): """Basic implementation of connector. State can be: "connecting", "connected", "disconnected" """ implements(IConnector) timeoutID = None factoryStarted = 0 def __init__(self, factory, timeout, reactor):