hack.py 584 B

1234567891011121314151617181920212223242526272829303132
  1. # The hackable utils lib for TitleBot
  2. import sys
  3. import os
  4. from threading import Thread
  5. def async(func):
  6. def exec_thread(*args):
  7. return Thread(group=None, target=func, args=args).start()
  8. return exec_thread
  9. def restart_program():
  10. sys.stderr.write("Restarting...\n")
  11. python = sys.executable
  12. os.execl(python, python, *sys.argv)
  13. class Signal(object):
  14. def __init__(self):
  15. self.__slots = set()
  16. def connect(self, slot):
  17. self.__slots.add(slot)
  18. def emit(self, *args):
  19. for slot in self.__slots:
  20. slot(*args)