Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Created February 7, 2017 08:19
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 LarsBergqvist/eed79645f61c3d1af3cc137d157cd9b1 to your computer and use it in GitHub Desktop.
Save LarsBergqvist/eed79645f61c3d1af3cc137d157cd9b1 to your computer and use it in GitHub Desktop.
Simple storage of states in a global dictionary
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