mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 00:38:57 +00:00
okay, NOW multithreading works properly, and can i just say: holy fuck it's SO MUCH FASTER
This commit is contained in:
parent
954544205e
commit
ac4cb2ab7a
2 changed files with 14 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ planning.txt
|
|||
*.pyc
|
||||
/debug
|
||||
lynnesbian.json
|
||||
test.py
|
||||
|
|
|
@ -191,22 +191,19 @@ def make_post(args):
|
|||
db.commit()
|
||||
c.close()
|
||||
|
||||
def do_in_pool(function, data, timeout=30, silent=False):
|
||||
with ProcessPool(max_workers=cfg['service_threads']) as p:
|
||||
index = 0
|
||||
future = p.map(function, data)
|
||||
iterator = future.result()
|
||||
|
||||
while True:
|
||||
def task_done(future):
|
||||
try:
|
||||
result = next(iterator)
|
||||
except StopIteration:
|
||||
# all threads are done
|
||||
break
|
||||
result = future.result() # blocks until results are ready
|
||||
except TimeoutError as error:
|
||||
if not silent: print("Timed out on {}.".format(data[index]))
|
||||
finally:
|
||||
index += 1
|
||||
if not future.silent: print("Timed out on {}.".format(future.function_data))
|
||||
|
||||
def do_in_pool(function, data, timeout=30, silent=False):
|
||||
with ProcessPool(max_workers=5, max_tasks=10) as pool:
|
||||
for i in data:
|
||||
future = pool.schedule(function, args=[i], timeout=timeout)
|
||||
future.silent = silent
|
||||
future.function_data = i
|
||||
future.add_done_callback(task_done)
|
||||
|
||||
def get_key():
|
||||
db = MySQLdb.connect(
|
||||
|
|
Loading…
Reference in a new issue