Created
February 16, 2023 16:38
-
-
Save Samg381/9cc5f78ac6ccb7b69b9f5bcbaabb6b0e to your computer and use it in GitHub Desktop.
Simple Python Threading Demo
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 threading | |
import time | |
Monitor = True | |
def thread_function(): | |
print("[Worker] worker created!") | |
while (Monitor == True): | |
print("[Worker] working...") | |
time.sleep(1) | |
print("[Worker] worker stopping!") | |
if __name__ == "__main__": | |
print("[Main] Creating worker") | |
x = threading.Thread(target=thread_function) | |
x.start() | |
time.sleep(8) | |
print("[Main] Stopping worker") | |
Monitor = False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment