def f(sem, q): with sem: pid = getpid() ts = time.time() msg = 'process: {} - timestamp: {}'.format(pid, ts) q.put(msg) time.sleep(3)
def f(lock, q): with lock: pid = getpid() ts = time.time() msg = 'process: {} - timestamp: {}'.format(pid, ts) q.put(msg) time.sleep(1)
def f(q): print("I'm process {}".format(getpid())) q.put([42, None, 'hello']) for i in range(3): q.put('Message no. {} ({})'.format(i, time.time())) time.sleep(1) print('Done')
def f(q): print("I'm process {}".format(getpid())) # q.put([42, None, 'hello']) # for i in range(3): # q.put('Message no. {} ({})'.format(i, time.time())) # time.sleep(1) # print('Done') print(q.get()) # prints "[42, None, 'hello']" consuming = True while consuming: try: res = q.get() print(res) except q.Empty as e: print('Queue empty!') consuming = False
def f(barrier, q): barrier.wait() pid = getpid() ts = time.time() msg = 'process: {} - timestamp: {}'.format(pid, ts) q.put(msg)
def f(q): print("I'm process", getpid()) q.put([42, None, 'hello']) time.sleep(5)