You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.py 814B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from threading import Thread
  2. import time
  3. from itertools import count
  4. class Modell(Thread):
  5. def __init__(self):
  6. Thread.__init__(self)
  7. self.running = True
  8. def stop(self):
  9. self.running = False
  10. def setFunktion(self, func, args=None, kwargs=None):
  11. self.func = func
  12. self.args = args or []
  13. self.kwargs = kwargs or {}
  14. def run(self):
  15. t = Thread(target=self.func, args=self.args, kwargs=self.kwargs)
  16. t.setDaemon(True)
  17. t.start()
  18. while self.running:
  19. time.sleep(0.1)
  20. def worker(self):
  21. i= 0
  22. while True:
  23. i = i+1
  24. print(i)
  25. time.sleep(0.05)
  26. c = Modell()
  27. c.setFunktion(c.worker)
  28. c.start()
  29. t = time.time()
  30. time.sleep(3)
  31. c.stop()