Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concurrent.future.thread._python_exit: continuing blocking while exceptions occureded on windows. #127282

Open
GoodenoughPhysicsLab opened this issue Nov 26, 2024 · 4 comments
Labels
OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@GoodenoughPhysicsLab
Copy link

GoodenoughPhysicsLab commented Nov 26, 2024

Bug report

Bug description:

on windows, Thread.join is sometimes terrible because exception can not interrupt its blocking.

import threading
import time

def task():
    while True:
        time.sleep(1)

t = threading.Thread(target=task)
t.start()
t.join()

you can't exit this program by Ctrl+C on windows.

we can easily fix it to let exceptions been raisen.

import threading
import time

def task():
    while True:
        time.sleep(1)

t = threading.Thread(target=task)
t.start()
while t.is_alive():
    t.join(timeout=2)

this is what I want to fix in _python_exit, which been registered in atexit-call and it costs me a lot of time to realize what's problem with my program.

I'll send pr soon.

CPython versions tested on:

3.9, 3.10, 3.11, 3.12

Operating systems tested on:

Windows

Linked PRs

@GoodenoughPhysicsLab GoodenoughPhysicsLab added the type-bug An unexpected behavior, bug, or error label Nov 26, 2024
GoodenoughPhysicsLab added a commit to GoodenoughPhysicsLab/cpython that referenced this issue Nov 26, 2024
GoodenoughPhysicsLab added a commit to GoodenoughPhysicsLab/cpython that referenced this issue Nov 26, 2024
@picnixz picnixz added the stdlib Python modules in the Lib dir label Nov 26, 2024
@ZeroIntensity
Copy link
Member

cc @zooba as the Windows expert. The reproducer can be killed by just CTRL+C-ing twice on Linux.

@zooba
Copy link
Member

zooba commented Nov 28, 2024

I would prefer to make PyThread_join_thread aware of _PyOS_SigintEvent so that it can abort its wait.

@zooba
Copy link
Member

zooba commented Nov 28, 2024

That said, I am certain we have discussed this before, and presumably it's not so easy. I don't remember exactly why, but there'll be an issue somewhere with details.

@GoodenoughPhysicsLab
Copy link
Author

That said, I am certain we have discussed this before, and presumably it's not so easy. I don't remember exactly why, but there'll be an issue somewhere with details.

No matter how difficult it is, I want to have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants