本文整理汇总了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)