Skip to content

Instantly share code, notes, and snippets.

@Brymes
Created March 4, 2024 09:31
Show Gist options
  • Save Brymes/7ba8eb4be7168ea6c13a40e8e5af987a to your computer and use it in GitHub Desktop.
Save Brymes/7ba8eb4be7168ea6c13a40e8e5af987a to your computer and use it in GitHub Desktop.
Python Threading Snippet
import threading
import time
# Function to be executed concurrently
def print_after_delay(text, delay):
time.sleep(delay)
print(text)
# Create multiple threads
thread1 = threading.Thread(target=print_after_delay, args=("Hello", 1))
thread2 = threading.Thread(target=print_after_delay, args=("World", 2))
# Start the threads
thread1.start()
thread2.start()
# Wait for threads to complete
thread1.join()
thread2.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment