Skip to content

Instantly share code, notes, and snippets.

@townie
Created July 25, 2018 23:55
Show Gist options
  • Save townie/5dcbb64d25bbdc8478518413f2bab871 to your computer and use it in GitHub Desktop.
Save townie/5dcbb64d25bbdc8478518413f2bab871 to your computer and use it in GitHub Desktop.
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