Exemple #1
0
def f(sem, q):
    with sem:
        pid = getpid()
        ts = time.time()
        msg = 'process: {} - timestamp: {}'.format(pid, ts)
        q.put(msg)
        time.sleep(3)
Exemple #2
0
def f(lock, q):
    with lock:
        pid = getpid()
        ts = time.time()
        msg = 'process: {} - timestamp: {}'.format(pid, ts)
        q.put(msg)
        time.sleep(1)
Exemple #3
0
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')
Exemple #4
0
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
Exemple #5
0
def f(barrier, q):
    barrier.wait()
    pid = getpid()
    ts = time.time()
    msg = 'process: {} - timestamp: {}'.format(pid, ts)
    q.put(msg)
Exemple #6
0
def f(q):
    print("I'm process", getpid())
    q.put([42, None, 'hello'])
    time.sleep(5)