PyCharm 不会在主线程以外的其他线程内的断点处停止

问题描述 投票:0回答:1

我有一个像这样的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并没有就此停止。但是,如果我在主线程中放置断点,它会停止在主线程中。

python multithreading pycharm ide
1个回答
1
投票

在最近的 pycharm(2022 和 2023)中,这也发生在我身上,这是因为我之前激活了“Gevent 兼容”选项。我停用后它开始工作。

enter image description here

其他回复提到为所有线程启用断点或修补 pydevd,但这不是我的情况。

© www.soinside.com 2019 - 2024. All rights reserved.