Skip to content

Commit

Permalink
Add thread
Browse files Browse the repository at this point in the history
  • Loading branch information
7pandeys committed Nov 8, 2024
1 parent 33c8afc commit e955a5d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Basic/Basic_Of_Python/src/thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import threading
import time

# Function that will be executed by the first thread
def print_numbers():
for i in range(1, 6):
print(f"Number: {i}")
time.sleep(1) # Simulate a time-consuming task

# Function that will be executed by the second thread
def print_letters():
for letter in ['A', 'B', 'C', 'D', 'E']:
print(f"Letter: {letter}")
time.sleep(1) # Simulate a time-consuming task

# Create two threads
thread1 = threading.Thread(target=print_numbers)
thread2 = threading.Thread(target=print_letters)

# Start the threads
thread1.start()
thread2.start()

# Wait for both threads to complete
thread1.join()
thread2.join()

print("Both threads have finished execution.")

0 comments on commit e955a5d

Please sign in to comment.