aboutsummaryrefslogtreecommitdiff
path: root/lib/worker.py
blob: a3ee435d3dde38ea565df6533a2c541845d71223 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import threading
import time

def name():
    return threading.currentThread().getName()

def worker(q):
    while True:
        part = q.get()

        if part is None:
            break

        do_work(part)
        time.sleep(0.05)
        q.task_done()

def do_work(part: dict):
    if part['type'] == "print":
        action_print(part['payload'])

def action_print(text: str):
    print('{0} - {1}'.format(name(), text))