Created
July 24, 2016 15:01
-
-
Save Kwpolska/a040de8b978dcc4c272c0571d456a382 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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) |
This file contains hidden or 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
#!/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