Created
February 7, 2017 08:19
-
-
Save LarsBergqvist/eed79645f61c3d1af3cc137d157cd9b1 to your computer and use it in GitHub Desktop.
Simple storage of states in a global dictionary
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
import threading | |
states = {} | |
lock = threading.Lock() | |
def get_state(groupNumber, buttonNumber): | |
key = str(groupNumber) + '_' + str(buttonNumber) | |
state = 'off' | |
lock.acquire() | |
try: | |
if key in states: | |
state = states[key] | |
finally: | |
lock.release() | |
return state | |
def set_state(groupNumber, buttonNumber, state): | |
key = str(groupNumber) + '_' + str(buttonNumber) | |
lock.acquire() | |
try: | |
states[key] = state | |
finally: | |
lock.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment