Python twisted.internet.interfaces.IReactorThreads() Examples

The following are 12 code examples of twisted.internet.interfaces.IReactorThreads(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.internet.interfaces , or try the search function .
Example #1
Source File: test_internet.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_lotsOfThreadsAreScheduledCorrectly(self):
        """
        L{IReactorThreads.callFromThread} can be used to schedule a large
        number of calls in the reactor thread.
        """
        def addAndMaybeFinish():
            self.counter += 1
            if self.counter == 100:
                self.deferred.callback(True)

        for i in range(100):
            self.schedule(addAndMaybeFinish)

        return self.deferred 
Example #2
Source File: test_internet.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_lotsOfThreadsAreScheduledCorrectly(self):
        """
        L{IReactorThreads.callFromThread} can be used to schedule a large
        number of calls in the reactor thread.
        """
        def addAndMaybeFinish():
            self.counter += 1
            if self.counter == 100:
                self.deferred.callback(True)

        for i in range(100):
            self.schedule(addAndMaybeFinish)

        return self.deferred 
Example #3
Source File: base.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def callFromThread(self, f, *args, **kw):
            """
            See L{twisted.internet.interfaces.IReactorThreads.callFromThread}.
            """
            assert callable(f), "%s is not callable" % (f,)
            # lists are thread-safe in CPython, but not in Jython
            # this is probably a bug in Jython, but until fixed this code
            # won't work in Jython.
            self.threadCallQueue.append((f, args, kw))
            self.wakeUp() 
Example #4
Source File: base.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def getThreadPool(self):
            """
            See L{twisted.internet.interfaces.IReactorThreads.getThreadPool}.
            """
            if self.threadpool is None:
                self._initThreadPool()
            return self.threadpool 
Example #5
Source File: base.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def callInThread(self, _callable, *args, **kwargs):
            """
            See L{twisted.internet.interfaces.IReactorThreads.callInThread}.
            """
            self.getThreadPool().callInThread(_callable, *args, **kwargs) 
Example #6
Source File: base.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def suggestThreadPoolSize(self, size):
            """
            See L{twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize}.
            """
            self.getThreadPool().adjustPoolsize(maxthreads=size) 
Example #7
Source File: test_internet.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_lotsOfThreadsAreScheduledCorrectly(self):
        """
        L{IReactorThreads.callFromThread} can be used to schedule a large
        number of calls in the reactor thread.
        """
        def addAndMaybeFinish():
            self.counter += 1
            if self.counter == 100:
                self.deferred.callback(True)

        for i in xrange(100):
            self.schedule(addAndMaybeFinish)

        return self.deferred 
Example #8
Source File: base.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def callFromThread(self, f, *args, **kw):
            """See twisted.internet.interfaces.IReactorThreads.callFromThread.
            """
            assert callable(f), "%s is not callable" % (f,)
            # lists are thread-safe in CPython, but not in Jython
            # this is probably a bug in Jython, but until fixed this code
            # won't work in Jython.
            self.threadCallQueue.append((f, args, kw))
            self.wakeUp() 
Example #9
Source File: base.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def callInThread(self, _callable, *args, **kwargs):
            """See twisted.internet.interfaces.IReactorThreads.callInThread.
            """
            if self.threadpool is None:
                self._initThreadPool()
            self.threadpool.callInThread(_callable, *args, **kwargs) 
Example #10
Source File: base.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def suggestThreadPoolSize(self, size):
            """See twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize.
            """
            if size == 0 and not self.threadpool:
                return
            if not self.threadpool:
                self._initThreadPool()
            self.threadpool.adjustPoolsize(maxthreads=size) 
Example #11
Source File: runner.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def _bail(self):
        from twisted.internet import reactor
        d = defer.Deferred()
        reactor.addSystemEventTrigger('after', 'shutdown',
                                      lambda: d.callback(None))
        reactor.fireSystemEvent('shutdown') # radix's suggestion
        treactor = interfaces.IReactorThreads(reactor, None)
        if treactor is not None:
            treactor.suggestThreadPoolSize(0)
        # As long as TestCase does crap stuff with the reactor we need to 
        # manually shutdown the reactor here, and that requires util.wait
        # :(
        # so that the shutdown event completes
        unittest.TestCase('mktemp')._wait(d) 
Example #12
Source File: detect.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, ifname: str, clock: IReactorThreads = None):
        if clock is None:
            clock = reactor
        self.clock = clock  # type: IReactorThreads
        self.ifname = ifname  # type: str
        self.servers = None  # type: set
        self.dhcpRequestsDeferredList = None  # type: DeferredList
        self.deferredDHCPRequests = []  # type: List[Deferred]
        self.transaction_id = make_dhcp_transaction_id()  # type: bytes