-
-
Save Sanix-Darker/2402b0e0fe1d1e34c00fd4f87676518e to your computer and use it in GitHub Desktop.
Worker thread is doing some task, logger thread log printed messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread, Event | |
event = Event() | |
def worker(number, outputs, exit_code): | |
msg = "=== Table de mulitiplication par {}".format(number) | |
outputs.append(msg) | |
for i in range(1, number): | |
msg = "{} * {} = {}".format(i, number, i*number) | |
outputs.append(msg) | |
print(msg) | |
exit_code[0] = 0 | |
def logger(outputs, exit_code): | |
log = [] | |
i = 0 | |
while 1: | |
n_log = len(log) | |
n_out = len(outputs) | |
if n_log < n_out: | |
print("log : {}".format(outputs[i])) | |
log.append(outputs) | |
i = i + 1 | |
if exit_code[0] == 0 and n_log == n_out: | |
break | |
out = [] | |
ex_code = [-1] | |
t1 = Thread(target=worker, args=(12, out, ex_code, )) | |
t2 = Thread(target=logger, args=(out, ex_code, )) | |
t1.start() | |
t2.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment