Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97877 > unrolled thread
| Started by | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| First post | 2015-10-22 16:38 +1100 |
| Last post | 2015-10-25 21:23 +0200 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.python
select.poll and ppoll Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-10-22 16:38 +1100
Re: select.poll and ppoll Paul Rubin <no.email@nospam.invalid> - 2015-10-22 00:30 -0700
Re: select.poll and ppoll Laura Creighton <lac@openend.se> - 2015-10-22 11:07 +0200
Re: select.poll and ppoll Marko Rauhamaa <marko@pacujo.net> - 2015-10-22 14:18 +0300
Re: select.poll and ppoll Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-10-25 22:30 +1100
Re: select.poll and ppoll Marko Rauhamaa <marko@pacujo.net> - 2015-10-25 21:21 +0200
Re: select.poll and ppoll Marko Rauhamaa <marko@pacujo.net> - 2015-10-25 21:23 +0200
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2015-10-22 16:38 +1100 |
| Subject | select.poll and ppoll |
| Message-ID | <56287672$0$11117$c3e8da3@news.astraweb.com> |
Using Python 2.6, don't hate me.
I have select.poll, but I'm looking for something like ppoll instead. From
the Linux man page:
ppoll()
The relationship between poll() and ppoll() is analogous to the
relationship between select(2) and pselect(2): like pselect(2),
ppoll() allows an application to safely wait until either a file
descriptor becomes ready or until a signal is caught.
Technically, *I* don't want this, it's one of my work-colleagues. He says:
"My high-level goal is to run a callback function whenever the alsa mixer
level changes. The C alsa API provides snd_mixer_elem_set_callback, but the
Python API (import alsaaudio) seems to need me to get poll(2) descriptors"
--
Steve
[toc] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2015-10-22 00:30 -0700 |
| Message-ID | <87lhavxsvn.fsf@jester.gateway.sonic.net> |
| In reply to | #97877 |
Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes: > I have select.poll, but I'm looking for something like ppoll instead. From > the Linux man page: I don't understand your post: do you have a question? Also I thought the current preferred practice was to use epoll.
[toc] | [prev] | [next] | [standalone]
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Date | 2015-10-22 11:07 +0200 |
| Message-ID | <mailman.87.1445504881.878.python-list@python.org> |
| In reply to | #97877 |
In a message of Thu, 22 Oct 2015 16:38:52 +1100, "Steven D'Aprano" writes: >Using Python 2.6, don't hate me. >Technically, *I* don't want this, it's one of my work-colleagues. He says: > >"My high-level goal is to run a callback function whenever the alsa mixer >level changes. The C alsa API provides snd_mixer_elem_set_callback, but the >Python API (import alsaaudio) seems to need me to get poll(2) descriptors" >-- >Steve > >-- >https://mail.python.org/mailman/listinfo/python-list Do you need alsa-mixer or would pulse-audio work for you? Would this: https://github.com/mk-fg/pulseaudio-mixer-cli do the job? Laura (alsa-mixer hater)
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2015-10-22 14:18 +0300 |
| Message-ID | <87eggnqhgq.fsf@elektro.pacujo.net> |
| In reply to | #97877 |
Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
> I have select.poll, but I'm looking for something like ppoll instead. From
> the Linux man page:
>
> ppoll()
> The relationship between poll() and ppoll() is analogous to the
> relationship between select(2) and pselect(2): like pselect(2),
> ppoll() allows an application to safely wait until either a file
> descriptor becomes ready or until a signal is caught.
>
> Technically, *I* don't want this, it's one of my work-colleagues. He
> says:
>
> "My high-level goal is to run a callback function whenever the alsa
> mixer level changes. The C alsa API provides
> snd_mixer_elem_set_callback, but the Python API (import alsaaudio)
> seems to need me to get poll(2) descriptors"
I've never used ppoll or pselect. They are used to fix naive signal
handling in a main loop:
while not signaled:
select.poll(...)
...
The loop suffers from a race condition: the "signaled" flag, which is
set by a signal handler, might change between "while" and "select.poll".
The standard, classic way to solve the race condition is to replace the
"signaled" flag with an internal pipe. The signal handler writes a byte
into the pipe and select.poll() wakes up when the pipe becomes readable.
IOW, ppoll() and pselect() are not needed.
Marko
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2015-10-25 22:30 +1100 |
| Message-ID | <562cbd56$0$1598$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #97893 |
On Thursday 22 October 2015 22:18, Marko Rauhamaa wrote: > Steven D'Aprano <steve+comp.lang.python@pearwood.info>: > >> I have select.poll, but I'm looking for something like ppoll instead. >> From the Linux man page: [...] > The standard, classic way to solve the race condition is to replace the > "signaled" flag with an internal pipe. The signal handler writes a byte > into the pipe and select.poll() wakes up when the pipe becomes readable. > IOW, ppoll() and pselect() are not needed. I don't know who is going to see this, if anyone, since mail.python.org is currently down, but thanks for this, and thanks to everyone else who answered. I will discuss with my colleague and see if this solves his problem. -- Steve
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2015-10-25 21:21 +0200 |
| Message-ID | <87pp02da9f.fsf@elektro.pacujo.net> |
| In reply to | #97941 |
Steven D'Aprano <steve+comp.lang.python@pearwood.info>: > On Thursday 22 October 2015 22:18, Marko Rauhamaa wrote: >> The standard, classic way to solve the race condition is to replace >> the "signaled" flag with an internal pipe. The signal handler writes >> a byte into the pipe and select.poll() wakes up when the pipe becomes >> readable. IOW, ppoll() and pselect() are not needed. > > [...] > > I will discuss with my colleague and see if this solves his problem. Note also that "newer" Linux kernels (2.6.25 and up) have a file descriptor type, signalfd, that simplifies the idiom slightly. Marko
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2015-10-25 21:23 +0200 |
| Message-ID | <87lhaqda6b.fsf@elektro.pacujo.net> |
| In reply to | #97951 |
Marko Rauhamaa <marko@pacujo.net>: > Note also that "newer" Linux kernels (2.6.25 and up) have a file > descriptor type, signalfd, that simplifies the idiom slightly. <URL: https://pypi.python.org/pypi/python-signalfd> <URL: https://pypi.python.org/pypi/signalfd> Haven't tried either. Marko
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web