我有一个像这样的Python多线程代码:
import concurrent.futures
import time
# Define a function to simulate a task that takes some time to complete
def some_task(seconds):
print(f"Starting task that will take {seconds} seconds...")
time.sleep(seconds)
print(f"Task completed after {seconds} seconds")
# Create a ThreadPoolExecutor with 3 worker threads
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
# Submit multiple tasks to the executor
task1 = executor.submit(some_task, 2)
task2 = executor.submit(some_task, 4)
task3 = executor.submit(some_task, 1)
# Wait for all tasks to complete and print their results
results = concurrent.futures.wait([task1, task2, task3], return_when=concurrent.futures.ALL_COMPLETED)
for result in results.done:
print(result.result())
我在函数
some_task
内设置了一个断点,但Pycharm并没有就此停止。但是,如果我在主线程中放置断点,它会停止在主线程中。