28 December, 2021 - 04:29 PM
(This post was last modified: 28 December, 2021 - 04:32 PM by clap. Edited 1 time in total.)
When you're dealing with non thread-safe tasks, use the lock. As an example, if you wanted to say call print, it wouldn't go smooth and multiple statements would be executed at the same time resulting in overlaps (text on same line). This would be a perfect time to call the lock.
Note: You should look into queues.
Note: You should look into queues.
Code:
import threading
lock = threading.Lock()
def worker():
with lock:
print('Text')
# Or
def worker():
lock.acquire()
print('Text')
lock.release()
Always confirm via PM before dealing with me.