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

pthread_kill() doesn't work on the main thread on FreeBSD6 #56601

Closed
vstinner opened this issue Jun 23, 2011 · 8 comments
Closed

pthread_kill() doesn't work on the main thread on FreeBSD6 #56601

vstinner opened this issue Jun 23, 2011 · 8 comments

Comments

@vstinner
Copy link
Member

BPO 12392
Nosy @vstinner
Files
  • thread_init_freebsd6.patch
  • pthread_kill_main_thread.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-06-26.20:29:28.401>
    created_at = <Date 2011-06-23.22:56:01.208>
    labels = []
    title = "pthread_kill() doesn't work on the main thread on FreeBSD6"
    updated_at = <Date 2011-11-08.17:31:01.153>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2011-11-08.17:31:01.153>
    actor = 'flox'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-06-26.20:29:28.401>
    closer = 'vstinner'
    components = []
    creation = <Date 2011-06-23.22:56:01.208>
    creator = 'vstinner'
    dependencies = []
    files = ['22431', '22445']
    hgrepos = []
    issue_num = 12392
    keywords = ['patch']
    message_count = 8.0
    messages = ['138875', '138876', '138877', '138970', '138973', '138974', '139596', '139806']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'neologix', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue12392'
    versions = ['Python 3.3']

    @vstinner
    Copy link
    Member Author

    pthread_kill() doesn't work on the main thread on FreeBSD6: sending a signal to the main thread does nothing. It works on the main thread just after the creation of the first thread.

    PyThread__init_thread() has 3 implementations in Python/thread_pthread.h:

    • call pthread_init()
    • create a dummy thread (no-op) and join it
    • do nothing

    pthread_init() doesn't exist on FreeBSD6. If the dummy thread implementation is used, pthread_kill() works directly on the main thread at startup.

    @vstinner
    Copy link
    Member Author

    Attached patch implements the suggested fix.

    @vstinner
    Copy link
    Member Author

    FreeBSD 7 is not affected by this issue.

    To test this issue, call signal.pthread_kill(threading.get_ident(), signal.SIGINT) in an interpreter: it should raise a KeyboardInterrupt. On FreeBSD6, it does nothing. Or run ./python -m test -v test_signal: test_pendings hangs because the test reads 3 bytes from a pipe whereas the pipe is empty. The write end is non blocking, but the read end is blocking.

    It would be possible to fix the test to fail instead of blocking: set the read end as non blocking (setUp() does always set the write end as non blocking).

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Jun 24, 2011

    Attached patch implements the suggested fix.

    The patch looks good to me.

    It would be possible to fix the test to fail instead of blocking

    I think this issue deserves a specific test, since:

    • test_pending tests something completely different
    • at the time test_pending gets to run, there's a high chance that
      threads have already been created

    I've attached a patch spawning a new interpreter to test that.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 24, 2011

    New changeset 024827a9db64 by Victor Stinner in branch 'default':
    Issue bpo-12392: fix thread initialization on FreeBSD 6
    http://hg.python.org/cpython/rev/024827a9db64

    @vstinner
    Copy link
    Member Author

    I've attached a patch spawning a new interpreter to test that.

    Thanks, I commited your test at the same time of the fix.

    @vstinner
    Copy link
    Member Author

    vstinner commented Jul 1, 2011

    This issue introduced regressions in the faulthandler module: see issue bpo-12469.

    @vstinner
    Copy link
    Member Author

    vstinner commented Jul 4, 2011

    As discussed in issue bpo-12469, the commit 024827a9db64 makes things worse: it changes the behaviour of many functions related to signal handling (e.g. sigwait()) just to be able to use pthread_kill() on the main thread. I reverted the patch: commit 34061f0d35ba.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant