Last active
July 10, 2020 08:19
-
-
Save simryang/cfbddc0b010b05e1491fee7cc7e2f146 to your computer and use it in GitHub Desktop.
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 time | |
import threading | |
class testthread(threading.Thread): | |
def __init__(self, testvar=None): | |
threading.Thread.__init__(self) | |
self.enabled = False | |
def stop(self): | |
self.enabled = False | |
def enable(self): | |
self.enabled = True | |
def run(self): | |
try: | |
while self.enabled: | |
print('1') | |
time.sleep(0.1) | |
except Exception as e: | |
pass | |
if __name__ == '__main__': | |
ttest = testthread('abcd') | |
ttest.enable() | |
ttest.start() | |
time.sleep(0.001) | |
ttest.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set enabled flag by calling ttest.enable()
Unset enabled flag by calling ttest.stop()