Blocking I/O affecting other threads?

Clarence Gardner clarence at netlojix.com
Thu Oct 12 04:40:10 EDT 2000


Hello again.  Not surprisingly, I've found that this is not a Python
threading problem.  (I did this by adding a thread to the program
that just periodically printed out something.)  I then built a Python
that, immediately after doing the fread at the heart of file.read(),
printed out how many bytes it head read.  Curiously, doing
  open('/etc/passwd').read(10)
printed
  read 10 bytes
  read 0 bytes
I never really understood that, but it got me to thinking about EOF
statuses.  Of course, the read that I do shouldn't get an EOF, because
the preceding select() indicated data present.  I tried adding a clearerr()
unconditionally after the fread (the code already does one if ferror() is
true, but for feof()), which had no effect.  I still didn't understand
what was going on, but finally remembering that the object I was reading
was an instance of a class I've had to use on Solaris to use sockets with
file-expecting functions (because Solaris stdio doesn't work on sockets
if you both read them and write them, so the class does two makefile()s
and directs read/write/etc calls to the appropriate one), I tried using
the socket's recv() method instead of a read.

Voila! No more problem.  I still don't understand what the reading
thread was doing, particularly because at one point I had modified my
function to have this:
        if not x:
                print '0 bytes read, exiting'
                break
instead of:
        if not x:
                break

and it *still* didn't print anything.

Well, I know when I'm licked.  recv() it is.......
I hope you enjoyed my diatribes!

ashamed-to-have-even-for-a-second-suspected-Python-ly,
Clarence

--
Clarence Gardner
Software Engineer
NetLojix Communications
clarence at netlojix.com




More information about the Python-list mailing list