Threads and Event - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Threads and Event (/thread-8810.html) |
Threads and Event - ricardons - Mar-08-2018 this is not working I don't understand this threading.Event what i am doing wrong? import threading import numpy as np from time import sleep def read(): event_rd.wait() #should be run when x>50 print("read is running") def read_write(): event_rdw.wait() #should be run when x<50 print("read_write is running") def detect(): while True: x= np.random.randint(1,100) if x > 50: if event_rdw.is_set(): event_rdw.clear() print("read_write paused") event_rd.set() # code if x < 50: if event_rd.is_set(): event_rd.clear() print("read paused") event_rdw.set() # code sleep(2) event_rd = threading.Event # restart read() and pause read_write() event_rdw = threading.Event # restart read_write ans pause read() event_rd.set() event_rdw.set() t_main = threading.Thread(target=detect, name="detect") t_main.start() t_rd = threading.Thread(target=read, name="read") t_rdw = threading.Thread(target=read_write, name="read_write") t_rd.start() t_rdw.start()error log
RE: Threads and Event - Larz60+ - Mar-08-2018 more info and examples for threading here: https://pymotw.com/3/threading/ |