Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created July 24, 2016 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kwpolska/a040de8b978dcc4c272c0571d456a382 to your computer and use it in GitHub Desktop.
Save Kwpolska/a040de8b978dcc4c272c0571d456a382 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from enum import Enum
from queue import Queue, Empty
class Action(Enum):
addMessage = 1
def mainLoop(q):
while True:
action = q[0] #.get_nowait()
print(isinstance(action[0], Action)) # False
print(isinstance(Action.addMessage, Action)) # True
if action[0] == Action.addMessage:
print('Adding message...')
else:
print('Module requested unknown action {}'.format(action[0]))
exit(0) # Test over
print('main', id(Action))
from module import Module
# Set up a queue so that the module can communicate with the main thread
q = [] #Queue()
# This will (correctly) fail if the module doesn't implement all necessary
# functionality
module = Module(q)
# Run forever
mainLoop(q)
#!/usr/bin/env python3
from main import Action
class Module():
def __init__(self, q):
q.append([Action.addMessage, "message"])
print('module', id(Action))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment