This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author neologix
Recipients georg.brandl, loewis, neologix, nijel, pitrou, r.david.murray
Date 2011-01-06.08:18:41
SpamBayes Score 7.923497e-08
Marked as misclassified No
Message-id <AANLkTimQ0hz17QtsjAtR4t=0pF2Nvqt19ZNK5YXAf_9F@mail.gmail.com>
In-reply-to <4D23A133.9090906@v.loewis.de>
Content
> Martin v. Löwis <martin@v.loewis.de> added the comment:
>
>> "It's a bug in random.c that doesn' t check for signal pending inside the
>> read(2) code, so you have no chance to kill the process via signals until
>> the read(2) syscall is finished, and it could take a lot of time before
>> return, if the buffer given to the read syscall is very big..."
>>
>> I've had a quick look at the source code, and indeed, read(2) from
>> /dev/urandom can now be interrupted by a signal, so looping seems to
>> be justified.
>
> No: if read(2) is interrupted, no data is returned, and exception is
> raised. So it won't loop in that case, but raise the exception out of
> urandom also (which is the right thing to do).
>

(Sorry for being a little off-topic, but since there's not dedicated thread)
Try with this:
dd if=/dev/urandom of=/dev/null bs=100M count=1

Then, in another terminal:
pkill -USR1 -xn dd

You'll see that read returns less that 100M bytes when interrupted.
You can also try with the following python code:

---
import os

d = os.open('/dev/urandom', os.O_RDONLY)
data = os.read(d, 1 << 28)
os.close(d)
print('read %d bytes' % len(data))
---

and in another terminal
pkill -STOP -xn python
then
pkill -CONT -xn python

Same thing, read returns less bytes than requested.
Anyway, since /dev/urandom is not part of any standard (AFAIK), it's
probably better to use the common idiom
while len(data) < expected:
    read(expected - len(data))

So we're sure it won't break under some systems/conditions.

Cheers

> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue10824>
> _______________________________________
>
History
Date User Action Args
2011-01-06 08:18:43neologixsetrecipients: + neologix, loewis, georg.brandl, nijel, pitrou, r.david.murray
2011-01-06 08:18:41neologixlinkissue10824 messages
2011-01-06 08:18:41neologixcreate