from lithops.multiprocessing import Pool, Semaphore, SimpleQueue, getpid import time def f(sem, q): with sem: pid = getpid() ts = time.time() msg = 'process: {} - timestamp: {}'.format(pid, ts) q.put(msg) time.sleep(3) if __name__ == "__main__": # inital value to 3 sem = Semaphore(value=3) q = SimpleQueue() n = 6 with Pool() as p: p.map_async(f, [[sem, q]] * n) for _ in range(n): print(q.get())
import time from lithops.multiprocessing import Pool, Barrier, SimpleQueue, current_process def f(b, q): b.wait() pid = current_process().pid ts = time.time() msg = 'process: {} - timestamp: {}'.format(pid, ts) q.put(msg) if __name__ == "__main__": q = SimpleQueue() n = 4 barrier = Barrier(n) with Pool() as p: p.map_async(f, [[barrier, q]] * (n - 1)) # all - 1 print('Result queue empty:', q.empty()) time.sleep(3) p.apply_async(f, [barrier, q]) for _ in range(n): print(q.get())
from lithops.multiprocessing import Process, SimpleQueue def f(q): q.put([42, None, 'hello World']) if __name__ == '__main__': q = SimpleQueue() p = Process(target=f, args=(q, )) p.start() print(q.get()) # prints "[42, None, 'hello']" p.join()