flatcam/appPool.py

33 lines
756 B
Python
Raw Permalink Normal View History

2019-01-03 19:25:08 +00:00
from PyQt5 import QtCore
from multiprocessing import Pool, cpu_count
2019-01-03 19:25:08 +00:00
import dill
2019-07-16 17:51:09 +00:00
2019-01-03 19:25:08 +00:00
def run_dill_encoded(what):
fun, args = dill.loads(what)
print("load", fun, args)
return fun(*args)
2019-07-16 17:51:09 +00:00
2019-01-03 19:25:08 +00:00
def apply_async(pool, fun, args):
print("...", fun, args)
print("dumps", dill.dumps((fun, args)))
return pool.map_async(run_dill_encoded, (dill.dumps((fun, args)),))
2019-07-16 17:51:09 +00:00
2019-01-03 19:25:08 +00:00
def func1():
print("func")
2019-01-03 19:25:08 +00:00
class WorkerPool(QtCore.QObject):
def __init__(self):
super(WorkerPool, self).__init__()
self.pool = Pool(cpu_count())
2019-01-03 19:25:08 +00:00
def add_task(self, task):
print("adding task", task)
# task['fcn'](*task['params'])
# print self.pool.map(task['fcn'], task['params'])
apply_async(self.pool, func1, ())