Created
July 25, 2018 23:55
-
-
Save townie/5dcbb64d25bbdc8478518413f2bab871 to your computer and use it in GitHub Desktop.
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 | |
q = [] | |
running = True | |
def publish(thing): | |
print('publishing: {}'.format(thing)) | |
q.append(thing) | |
def consumer(): | |
global q | |
global running | |
while running: | |
if len(q) > 0: | |
print("consuming: {}".format(q.pop(0))) | |
if __name__ == '__main__': | |
t = None | |
try: | |
t = Thread(target=consumer) | |
t.start() | |
except KeyboardInterrupt: | |
global running | |
running = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment