Python twisted.internet.reactor.threadpool() Examples
The following are 9
code examples of twisted.internet.reactor.threadpool().
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.reactor
, or try the search function
.
Example #1
Source File: threads.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def install_default_pool(maxthreads=max_threads_for_default_pool): """Install a custom pool as Twisted's global/reactor thread-pool. Disallow all database activity in the reactor thread-pool. Why such a strict policy? We've been following Django's model, where threads and database connections are wedded together. In MAAS this limits concurrency, contributes to crashes and deadlocks, and has spawned workarounds like post-commit hooks. From here on, using a database connection requires the use of a specific, separate, carefully-sized, thread-pool. """ if reactor.threadpool is None: # Start with ZERO threads to avoid pulling in all of Django's # configuration straight away; it may not be ready yet. reactor.threadpool = make_default_pool(maxthreads) reactor.callWhenRunning(reactor.threadpool.start) reactor.addSystemEventTrigger( "during", "shutdown", reactor.threadpool.stop ) else: raise AssertionError( "Too late; global/reactor thread-pool has " "already been configured and installed." )
Example #2
Source File: util.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def postClassCleanup(self): """ Called by L{unittest.TestCase} after the last test in a C{TestCase} subclass. Ensures the reactor is clean by murdering the threadpool, catching any pending L{DelayedCall<twisted.internet.base.DelayedCall>}s, open sockets etc. """ selectables = self._cleanReactor() calls = self._cleanPending() if selectables or calls: aggregate = DirtyReactorAggregateError(calls, selectables) self.result.addError(self.test, Failure(aggregate)) self._cleanThreads()
Example #3
Source File: util.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def _cleanThreads(self): reactor = self._getReactor() if interfaces.IReactorThreads.providedBy(reactor): if reactor.threadpool is not None: # Stop the threadpool now so that a new one is created. # This improves test isolation somewhat (although this is a # post class cleanup hook, so it's only isolating classes # from each other, not methods from each other). reactor._stopThreadPool()
Example #4
Source File: util.py From learn_python3_spider with MIT License | 5 votes |
def postClassCleanup(self): """ Called by L{unittest.TestCase} after the last test in a C{TestCase} subclass. Ensures the reactor is clean by murdering the threadpool, catching any pending L{DelayedCall<twisted.internet.base.DelayedCall>}s, open sockets etc. """ selectables = self._cleanReactor() calls = self._cleanPending() if selectables or calls: aggregate = DirtyReactorAggregateError(calls, selectables) self.result.addError(self.test, Failure(aggregate)) self._cleanThreads()
Example #5
Source File: util.py From learn_python3_spider with MIT License | 5 votes |
def _cleanThreads(self): reactor = self._getReactor() if interfaces.IReactorThreads.providedBy(reactor): if reactor.threadpool is not None: # Stop the threadpool now so that a new one is created. # This improves test isolation somewhat (although this is a # post class cleanup hook, so it's only isolating classes # from each other, not methods from each other). reactor._stopThreadPool()
Example #6
Source File: util.py From python-for-android with Apache License 2.0 | 5 votes |
def postClassCleanup(self): """ Called by L{unittest.TestCase} after the last test in a C{TestCase} subclass. Ensures the reactor is clean by murdering the threadpool, catching any pending L{DelayedCall}s, open sockets etc. """ selectables = self._cleanReactor() calls = self._cleanPending() if selectables or calls: aggregate = DirtyReactorAggregateError(calls, selectables) self.result.addError(self.test, Failure(aggregate)) self._cleanThreads()
Example #7
Source File: util.py From python-for-android with Apache License 2.0 | 5 votes |
def _cleanThreads(self): reactor = self._getReactor() if interfaces.IReactorThreads.providedBy(reactor): if reactor.threadpool is not None: # Stop the threadpool now so that a new one is created. # This improves test isolation somewhat (although this is a # post class cleanup hook, so it's only isolating classes # from each other, not methods from each other). reactor._stopThreadPool()
Example #8
Source File: util.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def do_cleanThreads(cls): from twisted.internet import reactor if interfaces.IReactorThreads.providedBy(reactor): reactor.suggestThreadPoolSize(0) if hasattr(reactor, 'threadpool') and reactor.threadpool: reactor.threadpool.stop() reactor.threadpool = None # *Put it back* and *start it up again*. The # reactor's threadpool is *private*: we cannot just # rape it and walk away. reactor.threadpool = threadpool.ThreadPool(0, 10) reactor.threadpool.start()
Example #9
Source File: test_threads.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_default_pool_is_disconnected_pool(self): pool = reactor.threadpool self.assertThat(pool, IsInstance(ThreadPool)) self.assertThat( pool.context.contextFactory, Is(orm.TotallyDisconnected) ) self.assertThat(pool.min, Equals(0))