Python multiprocessing.BoundedSemaphore() Examples

The following are 6 code examples of multiprocessing.BoundedSemaphore(). 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 multiprocessing , or try the search function .
Example #1
Source File: Zydra.py    From Zydra with MIT License 5 votes vote down vote up
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 
Example #2
Source File: _test_multiprocessing.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #3
Source File: _test_multiprocessing.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
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) 
Example #4
Source File: executor.py    From medaka with Mozilla Public License 2.0 5 votes vote down vote up
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) 
Example #5
Source File: executor.py    From medaka with Mozilla Public License 2.0 5 votes vote down vote up
def __init__(self, max_items, **kwargs):
        """Initialize a thread 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 `ThreadPoolExecutor`.
        """
        super().__init__(**kwargs)
        self.semaphore = threading.BoundedSemaphore(max_items) 
Example #6
Source File: _test_multiprocessing.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
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)