Pop-Up Thingie

>>> Magnum BBS <<<
  • Home
  • Forum
  • Files
  • Log in

  1. Forum
  2. Usenet
  3. COMP.LANG.PYTHON
  • Calling pselect/ppoll/epoll_pwait

    From Ian Pilcher@21:1/5 to All on Fri Dec 2 14:00:21 2022
    Does Python provide any way to call the "p" variants of the I/O
    multiplexing functions?

    Looking at the documentation of the select[1] and selectors[2] modules,
    it appears that they expose only the "non-p" variants.

    [1] https://docs.python.org/3/library/select.html
    [2] https://docs.python.org/3/library/selectors.html

    --
    ========================================================================
    Google Where SkyNet meets Idiocracy ========================================================================

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Barry@21:1/5 to All on Sat Dec 3 00:00:34 2022
    On 2 Dec 2022, at 20:03, Ian Pilcher <arequipeno@gmail.com> wrote:

    Does Python provide any way to call the "p" variants of the I/O multiplexing functions?

    Looking at the documentation of the select[1] and selectors[2] modules,
    it appears that they expose only the "non-p" variants.

    [1] https://docs.python.org/3/library/select.html
    [2] https://docs.python.org/3/library/selectors.html

    Can you use signalfd and select/poll/epoll?

    Barry


    --
    ======================================================================== Google Where SkyNet meets Idiocracy ========================================================================
    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Barry@21:1/5 to All on Sun Dec 4 09:55:24 2022
    On 3 Dec 2022, at 13:13, Weatherby,Gerard <gweatherby@uchc.edu> wrote:

    

    Signalfd and select could probably be made to work if one codes around
    the race conditions pselect is provided to avoid. I’m not sure if using
    the GIL (for CPython) is sufficient or if a dedicated concurrency
    control (e.g. lock, mutex, semaphore) is necessary.

    An alternative is to call the C library function via a wrapper. I had
    need to use setfsuid on a project a couple of years ago and found this
    example:

    [1]https://gist.github.com/atdt/ebafa299e843a767139b

     

    I read this on SO when researching your question.
    Search for epoll and signal.

    (I would post the link but ipad turns the link into an image…)

    I assume that the lack of pepoll means you can use epoll and

    signalfd without race conditions. The trick seems to be setting

    the signal to ignore.

    Barry

     

    From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org>
    on behalf of Barry <barry@barrys-emacs.org>

    Date: Friday, December 2, 2022 at 7:02 PM
    To: Ian Pilcher <arequipeno@gmail.com>
    Cc: python-list@python.org <python-list@python.org>
    Subject: Re: Calling pselect/ppoll/epoll_pwait

    *** Attention: This is an external email. Use caution responding,
    opening attachments or clicking on links. ***

    > On 2 Dec 2022, at 20:03, Ian Pilcher <arequipeno@gmail.com> wrote:
    >
    > Does Python provide any way to call the "p" variants of the I/O
    > multiplexing functions?
    >
    > Looking at the documentation of the select[1] and selectors[2]
    modules,
    > it appears that they expose only the "non-p" variants.
    >
    > [1]
    [2]https://urldefense.com/v3/__https://docs.python.org/3/library/select.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_OD5qBjeA$
    > [2]
    [3]https://urldefense.com/v3/__https://docs.python.org/3/library/selectors.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_MwNjgO8A$

    Can you use signalfd and select/poll/epoll?

    Barry

    >
    > --
    >
    ========================================================================
    > Google                                      Where SkyNet meets
    Idiocracy
    >
    ========================================================================
    > --
    >
    [4]https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$
    >

    --
    [5]https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$

    References

    Visible links
    1. https://gist.github.com/atdt/ebafa299e843a767139b
    2. https://urldefense.com/v3/__https:/docs.python.org/3/library/select.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_OD5qBjeA$
    3. https://urldefense.com/v3/__https:/docs.python.org/3/library/selectors.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_MwNjgO8A$
    4. https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$
    5. https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ian Pilcher@21:1/5 to Ian Pilcher on Tue Dec 13 12:50:34 2022
    On 12/2/22 14:00, Ian Pilcher wrote:
    Does Python provide any way to call the "p" variants of the I/O
    multiplexing functions?

    Just to close this out ...

    As others suggested, there's no easy way to call the "p" variants of the
    I/O multiplexing functions, but this can be worked around by "mapping"
    signals to file descriptors.

    There are a few ways to accomplish this.

    1. Use a Linux signalfd. There's at least one library out there that
    provides signalfd support to Python.

    2. Use signal.set_wakeup_fd()[1]. I didn't really explore this, as it
    appears that there isn't any way to filter the signals that will be
    reported.

    3. Roll your own. This turned out to be really simple for my use case,
    which is simply to set an exit flag and wake my program up if it
    receives SIGINT or SIGTERM.

    _sel = selectors.DefaultSelector()
    _exit_flag = False
    _sig_pipe_r, _sig_pipe_w = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC)

    def _sig_handler(signum, frame):
    global _exit_flag
    _exit_flag = True
    os.write(_sig_pipe_w, b'\x00')

    _sel.register(_sig_pipe_r, selectors.EVENT_READ)
    # register other file descriptors of interest
    signal.signal(signal.SIGINT, _sig_handler)
    signal.signal(signal.SIGTERM, _sig_handler)
    while not _exit_flag:
    ready = _sel.select()
    # handle other file descriptors

    [1] https://docs.python.org/3/library/signal.html#signal.set_wakeup_fd

    --
    ========================================================================
    Google Where SkyNet meets Idiocracy ========================================================================

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • Who's Online

  • System Info

    Sysop: Keyop
    Location: Huddersfield, West Yorkshire, UK
    Users: 546
    Nodes: 16 (2 / 14)
    Uptime: 14:51:45
    Calls: 10,389
    Files: 14,061
    Messages: 6,416,903

© >>> Magnum BBS <<<, 2025