Skip to content

Instantly share code, notes, and snippets.

@noqqe
Created February 20, 2019 06:27
Show Gist options
  • Save noqqe/04fbc58fc6426ed07e7719ee5c4c9e90 to your computer and use it in GitHub Desktop.
Save noqqe/04fbc58fc6426ed07e7719ee5c4c9e90 to your computer and use it in GitHub Desktop.
A spike to test reading from 2 sources in parallel without blocking
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import signal
import threading
import time
def login():
k = threading.Thread(target=keyboard)
r = threading.Thread(target=rfid)
k.start()
r.start()
def keyboard():
lock = threading.Lock()
while True:
with lock:
user = input("keyboard> ")
if user == 'lol':
menu("keyboard")
def rfid():
signal.signal(signal.SIGHUP, menu("rfid"))
def menu(source):
while True:
print("You are in menu as %s" % source)
print("1: FOO")
print("2: BAR")
input("> ")
def main():
login()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment