def setUp(self): self.executor = EnhancedThreadPoolExecutor( name='TestSerializingAsynchronizerExecutor', max_workers=1, ) self.asynchronizer = SerializingAsynchronizer( name='TestSerializingAsynchronizer', executor=self.executor, )
def setUp(self): self.executor = EnhancedThreadPoolExecutor( name='TestSerializerExecutor', max_workers=1) self.serializer = Serializer( name='TestSerializer', executor=self.executor, )
def test_del_shutdown(self): executor = EnhancedThreadPoolExecutor(max_workers=5) executor.map(abs, range(-5, 5)) threads = executor._threads del executor for t in threads: t.join()
def test_context_manager_shutdown(self): with EnhancedThreadPoolExecutor(max_workers=5) as e: executor = e self.assertEqual(list(e.map(abs, range(-5, 5))), [5, 4, 3, 2, 1, 0, 1, 2, 3, 4]) for t in executor._threads: t.join()
def setUp(self): self.executor = EnhancedThreadPoolExecutor( name='TestAsynchronizerExecutor', max_workers=1) self.asynchronizer = DelayedAsynchronizer( name='TestAsynchronizer', executor=self.executor, interval=0.5, )
def test_uninitialize(self): num_workers = 5 self.artifacts = [] def uninitialize(): self.artifacts.append(None) executor = EnhancedThreadPoolExecutor(num_workers, uninitializer=uninitialize) _start_all_threads(executor, num_workers) executor.shutdown(wait=True) self.assertEqual([None] * num_workers, self.artifacts)
def test_name(self): # Unnamed executor. executor = EnhancedThreadPoolExecutor(max_workers=5) with executor as e: # Start some threads. for _ in xrange(10): e.submit(pow, 2, 2) expected_prefix = "{0}Worker-".format(type(e).__name__) for t in e._threads: self.assertTrue(t.name.startswith(expected_prefix)) # Workers should all have different names. thread_names = [t.name for t in e._threads] self.assertEqual( len(set(thread_names)), len(thread_names), msg="Threads don't have unique names: {0}.".format( thread_names)) # Executor with explicit name. executor = EnhancedThreadPoolExecutor(max_workers=5, name="DeadParrotExecutioner") with executor as e: self.assertEqual(e.name, "DeadParrotExecutioner") # Start some threads. for _ in xrange(10): e.submit(pow, 2, 2) expected_prefix = "DeadParrotExecutionerWorker-" for t in e._threads: self.assertTrue(t.name.startswith(expected_prefix)) # Workers should all have different names. thread_names = [t.name for t in e._threads] self.assertEqual( len(set(thread_names)), len(thread_names), msg="Threads don't have unique names: {0}.".format( thread_names))
def __executor_default(self): # TIP: The executor should be 'shutdown' when no longer needed to avoid # creating multiple idle threads. This is not necessary in a small # demo. return EnhancedThreadPoolExecutor(max_workers=1)