Skip to content

Instantly share code, notes, and snippets.

@rbricheno
Created August 28, 2019 17:29
Show Gist options
  • Save rbricheno/e9782a26ffa45c1d8c75807a4d4fbd60 to your computer and use it in GitHub Desktop.
Save rbricheno/e9782a26ffa45c1d8c75807a4d4fbd60 to your computer and use it in GitHub Desktop.
import time
from threading import Thread
class HoldDownOrchestrator():
def __init__(self):
self.call = None
hold_down_singleton = HoldDownOrchestrator()
def hold_down(a_function, timer, *args, **kwargs):
global hold_down_singleton
hold_down_singleton.call = None
a_function(*args, **kwargs)
time.sleep(timer)
hold_down_singleton.call = hold_down
hold_down_singleton.call = hold_down
def function_to_hold_down(*args, **kwargs):
print("Hello!")
while True:
print("Pressing!")
thread1 = Thread(target=hold_down_singleton.call, args=[function_to_hold_down, 5])
thread1.start()
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment