Created
April 3, 2023 21:05
-
-
Save alyoshenka/f53b6e9b1481b9d2d608be092c488f13 to your computer and use it in GitHub Desktop.
Python Events Example
This file contains 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
import time | |
def main(q): | |
while True: | |
if q.not_empty: | |
event = q.get() | |
print('event:', event) | |
if event == 'exit': | |
return | |
else: | |
time.sleep(1) |
This file contains 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 | |
from boardsim import main as sim | |
from queue import Queue | |
def main(): | |
events = Queue() | |
events.put('hello') | |
events.put('world') | |
events.put('from') | |
t = Thread(target=sim, args=(events,)) | |
t.start() | |
events.put('threaded') | |
events.put('queue') | |
events.put('exit') | |
t.join() | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment