Using ioctl

Scott David Daniels scott.daniels at acm.org
Thu Feb 9 08:47:25 EST 2006


klappnase at web.de wrote:
>From reading the fcntl module's docs, I came to the following solution:
> 
>     try:
>         f = array.array('h', [0])
>         fcntl.ioctl(audio_fd, ossaudiodev.SNDCTL_DSP_GETBLKSIZE, f, 1)
>         frag_size = f.tolist()[0]
>     except:
>         frag_size = -1
>     if frag_size <= 0:
>         frag_size = 4096
> 
> I would feel more confident if anyone could explain how ioctl is supposed
 > to be used ( I also felt that I should use the try...except block for 
the
 > call in case it fails, but I don't have an idea "except *what*").
Fairly normal practice is to wait for a failure (or try to instigate
one) _without_ the try: ... except: ..., and then use the one you get.
Or, you could go for IOError, which sounds right to me.  remember your
current "except:" is catching any attempt at KeyBoardEscape (Control-C,
Control-Break, and such like).

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list