Skip to content

Instantly share code, notes, and snippets.

@Samg381
Created February 16, 2023 16:38
Show Gist options
  • Save Samg381/9cc5f78ac6ccb7b69b9f5bcbaabb6b0e to your computer and use it in GitHub Desktop.
Save Samg381/9cc5f78ac6ccb7b69b9f5bcbaabb6b0e to your computer and use it in GitHub Desktop.
Simple Python Threading Demo
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