本文整理匯總了Python中multiprocessing.BoundedSemaphore方法的典型用法代碼示例。如果您正苦於以下問題:Python multiprocessing.BoundedSemaphore方法的具體用法?Python multiprocessing.BoundedSemaphore怎麽用?Python multiprocessing.BoundedSemaphore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing
的用法示例。
在下文中一共展示了multiprocessing.BoundedSemaphore方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import BoundedSemaphore [as 別名]
def __init__(self):
self.start_time = time.monotonic()
self.process_lock = BoundedSemaphore(value=cpu_count())
self.counter_lock = threading.BoundedSemaphore(value=1)
self.banner()
self.stop = Queue(maxsize=1)
self.stop.put(False)
self.count = Queue(maxsize=1)
self.threads = []
self.name = Queue(maxsize=1)
self.name.put(str("a"))
self.process_count = 0
self.limit_process = 500
self.shot = 5000
示例2: test_bounded_semaphore
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import BoundedSemaphore [as 別名]
def test_bounded_semaphore(self):
sem = self.BoundedSemaphore(2)
self._test_semaphore(sem)
# Currently fails on OS/X
#if HAVE_GETVALUE:
# self.assertRaises(ValueError, sem.release)
# self.assertReturnsIfImplemented(2, get_value, sem)
示例3: __init__
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import BoundedSemaphore [as 別名]
def __init__(self, max_items, **kwargs):
"""Initialize a process pool.
:param max_items: maximum number of simultaneous work items.
Calls to `.submit` will block if there are too many unprocessed
items.
:param kwargs: key-word arguments to `ProcessPoolExecutor`.
"""
super().__init__(**kwargs)
self.semaphore = multiprocessing.BoundedSemaphore(max_items)