-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa368b1
commit 5f8c78b
Showing
12 changed files
with
319 additions
and
56 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import subprocess | ||
import threading | ||
import time | ||
|
||
# Example: Open Notepad | ||
# subprocess.run(["notepad.exe"]) | ||
subprocess.run(["explorer.exe"]) | ||
|
||
# Example: Open a specific file with its default application | ||
# subprocess.run(["C:\\Program Files\\Google\\Chrome Dev\\Application\\chrome.exe"]) | ||
# subprocess.run(["C:\\Windows\\System32\\calc.exe"]) | ||
|
||
|
||
|
||
def eat(): | ||
# time.sleep(2) | ||
print("eating break fast by ",threading.enumerate()) | ||
# subprocess.Popen(("open","C:\\Windows\\System32\\calc.exe")) | ||
|
||
def watchMovie(): | ||
# time.sleep(2) | ||
print("watching Movieby ",threading.enumerate()) | ||
|
||
def talking(): | ||
# time.sleep(2) | ||
print("talking with familyby ",threading.enumerate()) | ||
|
||
# sequential execution | ||
# eat() | ||
# watchMovie() | ||
# talking() | ||
|
||
# print(threading.active_count()) | ||
# print(threading.enumerate()) | ||
|
||
t1=threading.Thread(target=eat) | ||
t1.start() | ||
t2=threading.Thread(target=watchMovie) | ||
t2.start() | ||
t3=threading.Thread(target=talking) | ||
t3.start() | ||
|
||
t1.join() | ||
t2.join() | ||
t3.join() | ||
|
||
print(threading.active_count(),threading.enumerate()) | ||
print(time.perf_counter()) |
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# import threading | ||
|
||
# def print_numbers(): | ||
# for i in range(5): | ||
# print(i) | ||
|
||
# # Create a thread | ||
# thread = threading.Thread(target=print_numbers) | ||
|
||
# # Start the thread | ||
# thread.start() | ||
|
||
# # Wait for the thread to complete | ||
# thread.join() | ||
# print("Thread finished.") | ||
|
||
|
||
# import threading | ||
|
||
# def print_numbers(prefix): | ||
# for i in range(5): | ||
# print(f"{prefix} {i}") | ||
|
||
# # Create a thread with arguments | ||
# thread = threading.Thread(target=print_numbers, args=("Thread 1",)) | ||
|
||
# # Start the thread | ||
# thread.start() | ||
|
||
# # Wait for the thread to complete | ||
# thread.join() | ||
|
||
|
||
# import threading | ||
|
||
# lock = threading.Lock() | ||
|
||
# def thread_safe_function(): | ||
# with lock: | ||
# # Critical section of code | ||
# print("This section is thread-safe.") | ||
|
||
# thread = threading.Thread(target=thread_safe_function) | ||
# thread.start() | ||
# thread.join() | ||
|
||
|
||
|
||
import threading | ||
import requests | ||
|
||
def download_url(url): | ||
response = requests.get(url) | ||
print(f"Downloaded {url} with status code {response.status_code}") | ||
|
||
urls = [ | ||
"https://www.example.com", | ||
"https://www.python.org", | ||
"https://www.github.com" | ||
] | ||
|
||
threads = [] | ||
|
||
for url in urls: | ||
thread = threading.Thread(target=download_url, args=(url,)) | ||
threads.append(thread) | ||
thread.start() | ||
|
||
# Wait for all threads to complete | ||
for thread in threads: | ||
thread.join() | ||
|
||
print("All downloads finished.") |
Oops, something went wrong.