kopia lustrzana https://github.com/micropython/micropython-lib
multiprocessing: Add dummy Pool implementation which doesn't really uses pool.
rodzic
7fbc074a13
commit
b16a92a365
|
@ -60,3 +60,22 @@ def Pipe(duplex=True):
|
|||
assert duplex == False
|
||||
r, w = os.pipe()
|
||||
return Connection(r), Connection(w)
|
||||
|
||||
|
||||
class Pool:
|
||||
|
||||
def __init__(self, num):
|
||||
self.num = num
|
||||
|
||||
def apply(self, f, args=(), kwargs={}):
|
||||
# This is pretty inefficient impl, doesn't really use pool worker
|
||||
def _exec(w):
|
||||
r = f(*args, **kwargs)
|
||||
w.send(r)
|
||||
r, w = Pipe(False)
|
||||
p = Process(target=_exec, args=(w,))
|
||||
p.register_pipe(r, w)
|
||||
p.start()
|
||||
r = r.recv()
|
||||
p.join()
|
||||
return r
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
from multiprocessing import Pool
|
||||
|
||||
def f(x):
|
||||
return x*x
|
||||
|
||||
pool = Pool(4)
|
||||
print(pool.apply(f, (10,)))
|
Ładowanie…
Reference in New Issue