Beispiel #1
0
 def fastthreadpool_Semaphore_threads(self, values):
     s = fastthreadpool.Semaphore(8)
     pool = fastthreadpool.Pool()
     for value in values:
         if value & 1:
             pool.submit(self.release_cb, s)
         else:
             pool.submit(self.acquire_cb, s)
     pool.shutdown()
     return s.value
 def test_fastthreadpool_Semaphore_threads(self):
     s = fastthreadpool.Semaphore(8)
     pool = fastthreadpool.Pool()
     for value in range(10):
         if value & 1:
             pool.submit(self.release_cb, s)
         else:
             pool.submit(self.acquire_cb, s)
     pool.shutdown()
     assert s.value == 8
 def test_fastthreadpool_Semaphore(self):
     s = fastthreadpool.Semaphore(8)
     for _ in range(10):
         s.acquire()
         assert s.value == 7
         s.acquire()
         assert s.value == 6
         s.release()
         assert s.value == 7
         s.release()
         assert s.value == 8
     assert s.value == 8
Beispiel #4
0
import time
import threading
import fastthreadpool
from multiprocessing.pool import ThreadPool

t = time.time()
s = threading.Semaphore()
for _ in range(200000):
    s.release()
    s.acquire()
print("threading.Semaphore", time.time() - t)

t = time.time()
s = fastthreadpool.Semaphore()
for _ in range(200000):
    s.release()
    s.acquire()
print("fastthreadpool.Semaphore", time.time() - t)


def Worker(_i):
    s.release()
    s.acquire()


t = time.time()
pool = ThreadPool()
s.release()
s.release()
pool.map(Worker, range(200000))
Beispiel #5
0
 def fastthreadpool_Semaphore(values):
     s = fastthreadpool.Semaphore(8)
     for _ in values:
         s.release()
         s.acquire()
     return s.value