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

problem with siginterrupt #56433

Closed
ZhipingDeng mannequin opened this issue May 31, 2011 · 6 comments
Closed

problem with siginterrupt #56433

ZhipingDeng mannequin opened this issue May 31, 2011 · 6 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ZhipingDeng
Copy link
Mannequin

ZhipingDeng mannequin commented May 31, 2011

BPO 12224
Nosy @terryjreedy, @vstinner
Files
  • siginterrupt_example.py
  • 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-04.11:28:39.404>
    created_at = <Date 2011-05-31.11:23:34.181>
    labels = ['type-bug', 'library']
    title = 'problem with siginterrupt'
    updated_at = <Date 2011-06-04.13:12:38.221>
    user = 'https://bugs.python.org/ZhipingDeng'

    bugs.python.org fields:

    activity = <Date 2011-06-04.13:12:38.221>
    actor = 'Zhiping.Deng'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-06-04.11:28:39.404>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2011-05-31.11:23:34.181>
    creator = 'Zhiping.Deng'
    dependencies = []
    files = ['22207']
    hgrepos = []
    issue_num = 12224
    keywords = []
    message_count = 6.0
    messages = ['137357', '137360', '137611', '137631', '137634', '137637']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'vstinner', 'neologix', 'Zhiping.Deng']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue12224'
    versions = ['Python 2.7']

    @ZhipingDeng
    Copy link
    Mannequin Author

    ZhipingDeng mannequin commented May 31, 2011

    If socket timeout > 0, then there is no way to automatically
    restart some socket calls like recv().
    Calling siginterrupt(False) is useless, because python calls
    internal_select() if socket has timeout, and select returns
    error(EINTR) once interrupted by a signal, regardless of the
    SA_RESTART flags.

    So a user may have to wrap every socket calls in this case.

    I found some related discussions in http://bugs.python.org/issue7978

    @ZhipingDeng ZhipingDeng mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 31, 2011
    @vstinner
    Copy link
    Member

    Extract of manpage signal(7):

    "The following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR when interrupted by a signal handler:

    • ...
    • File descriptor multiplexing interfaces: epoll_wait(2), epoll_pwait(2), poll(2), ppoll(2), select(2), and pselect(2)."

    Consider siginterrupt(signal, False) as a "best-effort" trick... which doesn't work with select().

    If you don't want select() to be interrupted by SIGINT, use:

    pthread_sigmask(SIG_BLOCK, [SIGINT]);
    select(...)
    pthread_sigmask(SIG_UNBLOCK, [SIGINT])

    or

    pselect(...., [SIGINT])

    pselect() is atomic, whereas pthread_sigmask+select is not.

    I added recently pthread_sigmask() to the signal module in Python 3.3.

    pselect() is not exposed in Python currently. We may add it if it's needed.

    --

    If you really don't care of SIGINT, you can also ignore it completly using signal(SIGINT, SIG_IGN).

    @terryjreedy
    Copy link
    Member

    Victor, I understand your response as saying that there is no bug, which would suggest closing this. Correct? If not, what is the requested action?

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Jun 4, 2011

    Actually, it's part of a more general problem with EINTR being returned by many posix/socket module functions, see for example issue bpo-7978.
    On the one hand, having to retry manually on EINTR is cumbersome, on the other hand, some code might rely on this - receiving EINTR - and the posix module policy is to expose syscalls as-is.
    This should probably be closed as duplicate of issue bpo-9867.

    @vstinner
    Copy link
    Member

    vstinner commented Jun 4, 2011

    Victor, I understand your response as saying that there is no bug,
    which would suggest closing this. Correct? If not, what is
    the requested action?

    siginterrupt(False) has no effect on select().

    I listed some solutions to not interrupt select() on a signal (avoid completly EINTR). Issues bpo-7978 and bpo-9867 try the other solution, handle EINTR (retry select() on EINTR). I think that most users prefer the later (handle EINTR), so let's close as a duplicate.

    @zhiping Deng: Reopen the issue if you want the first solution :-)

    @vstinner vstinner closed this as completed Jun 4, 2011
    @ZhipingDeng
    Copy link
    Mannequin Author

    ZhipingDeng mannequin commented Jun 4, 2011

    I think the problem is that after a user calles signal.siginterrupt(False),
    he would expect that the socket.recv should handles EINTR properly
    for him because it's the behaviour in c level.
    He doesn't know socket.recv() calles select(2) internally and he needn't.

    Or at least this should be documented in signal.siginterrupt().

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants