當前位置: 首頁>>代碼示例>>Python>>正文


Python pool.map_async方法代碼示例

本文整理匯總了Python中multiprocessing.pool.map_async方法的典型用法代碼示例。如果您正苦於以下問題:Python pool.map_async方法的具體用法?Python pool.map_async怎麽用?Python pool.map_async使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在multiprocessing.pool的用法示例。


在下文中一共展示了pool.map_async方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_terminate

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_terminate(self):
        if self.TYPE == 'manager':
            # On Unix a forked process increfs each shared object to
            # which its parent process held a reference.  If the
            # forked process gets terminated then there is likely to
            # be a reference leak.  So to prevent
            # _TestZZZNumberOfObjects from failing we skip this test
            # when using a manager.
            return

        result = self.pool.map_async(
            time.sleep, [0.1 for i in range(10000)], chunksize=1
            )
        self.pool.terminate()
        join = TimingWrapper(self.pool.join)
        join()
        self.assertTrue(join.elapsed < 0.2) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:19,代碼來源:test_multiprocessing.py

示例2: test_map_chunksize

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_map_chunksize(self):
        try:
            self.pool.map_async(sqr, [], chunksize=1).get(timeout=TIMEOUT1)
        except multiprocessing.TimeoutError:
            self.fail("pool.map_async with chunksize stalled on null list") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_multiprocessing.py

示例3: test_terminate

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_terminate(self):
        p = self.Pool(4)
        result = p.map_async(
            time.sleep, [0.1 for i in range(10000)], chunksize=1
            )
        p.terminate()
        join = TimingWrapper(p.join)
        join()
        self.assertTrue(join.elapsed < 0.2) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_multiprocessing.py

示例4: test_empty_iterable

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_empty_iterable(self):
        # See Issue 12157
        p = self.Pool(1)

        self.assertEqual(p.map(sqr, []), [])
        self.assertEqual(list(p.imap(sqr, [])), [])
        self.assertEqual(list(p.imap_unordered(sqr, [])), [])
        self.assertEqual(p.map_async(sqr, []).get(), [])

        p.close()
        p.join() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_multiprocessing.py

示例5: test_map_async

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_map_async(self):
        self.assertEqual(self.pool.map_async(sqr, list(range(10))).get(),
                         list(map(sqr, list(range(10))))) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:_test_multiprocessing.py

示例6: test_map_async_callbacks

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_map_async_callbacks(self):
        call_args = self.manager.list() if self.TYPE == 'manager' else []
        self.pool.map_async(int, ['1'],
                            callback=call_args.append,
                            error_callback=call_args.append).wait()
        self.assertEqual(1, len(call_args))
        self.assertEqual([1], call_args[0])
        self.pool.map_async(int, ['a'],
                            callback=call_args.append,
                            error_callback=call_args.append).wait()
        self.assertEqual(2, len(call_args))
        self.assertIsInstance(call_args[1], ValueError) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:_test_multiprocessing.py

示例7: test_terminate

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_terminate(self):
        result = self.pool.map_async(
            time.sleep, [0.1 for i in range(10000)], chunksize=1
            )
        self.pool.terminate()
        join = TimingWrapper(self.pool.join)
        join()
        self.assertLess(join.elapsed, 0.5) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:10,代碼來源:_test_multiprocessing.py

示例8: test_terminate

# 需要導入模塊: from multiprocessing import pool [as 別名]
# 或者: from multiprocessing.pool import map_async [as 別名]
def test_terminate(self):
        result = self.pool.map_async(
            time.sleep, [0.1 for i in range(10000)], chunksize=1
            )
        self.pool.terminate()
        join = TimingWrapper(self.pool.join)
        join()
        # Sanity check the pool didn't wait for all tasks to finish
        self.assertLess(join.elapsed, 2.0) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:11,代碼來源:_test_multiprocessing.py


注:本文中的multiprocessing.pool.map_async方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。