Move file writes and reads to separate thread

This commit is contained in:
shortcutme 2019-11-19 02:16:20 +01:00
parent 5d113757df
commit 58214c0ac3
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
3 changed files with 71 additions and 3 deletions

View file

@ -0,0 +1,29 @@
import gevent
from util import ThreadPool
class TestThreadPool:
def testExecutionOrder(self):
pool = ThreadPool.ThreadPool(4)
events = []
@pool.wrap
def blocker():
events.append("S")
out = 0
for i in range(1000000):
out += 1
events.append("D")
return out
threads = []
for i in range(4):
threads.append(gevent.spawn(blocker))
gevent.joinall(threads)
assert events == ["S"] * 4 + ["D"] * 4, events
res = blocker()
assert res == 1000000