-
Notifications
You must be signed in to change notification settings - Fork 13
/
example.py
34 lines (23 loc) · 902 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from threading import Thread
from robotbackgroundlogger import BackgroundLogger
logger = BackgroundLogger()
threads = {}
def log_on_thread(message, level='INFO', html=False, name=None):
thread = Thread(name=name, target=logger.write, args=[message, level, html])
thread.start()
threads[thread.getName()] = thread
def log_on_threads(message, name_prefix, count):
for i in range(int(count)):
name = '%s %d' % (name_prefix, i+1)
thread = Thread(name=name, target=logger.info,
args=['%s says <i>%s</i>.' % (name, message)],
kwargs={'html': True})
thread.start()
threads[thread.getName()] = thread
def finish_all():
while threads:
threads.popitem()[1].join()
logger.log_background_messages()
def finish_one(name):
threads.pop(name).join()
logger.log_background_messages(name)