Threading problem

Niels Diepeveen niels at endea.demon.nl
Fri Aug 4 16:09:28 EDT 2000


Robert Cragie schreef:
> 
> I am having a problem with using threading and hope someone might be able to
> help me. I'm using Python 1.5.2 on Redhat Linux 6.1 (Kernel 2.2.12-20). It
> might be a bit off-topic in that it's concerning a device driver I have
> written too.
> 
> I have written a device driver which blocks on read() waiting for data. To
> test this, I have written a Python app. using wxPython. To perform the read,
> I spawn a thread using the 'threading' module, and this then does a blocking
> read() etc. This all seems to work fine. However the problem comes when I
> try to close the device from the main GUI thread. The spawned thread is
> blocked in read() using interruptible_sleep_on() a wait_queue. The close()
> function calls a wake_up_interruptible() to unblock the read() call, which
> will then exit with EINTR. That's the theory...

There is a minor flaw in the theory, as you may have guessed. To keep
you out of trouble, the kernel will close the file descriptor, but won't
actually close the device until it's no longer in use, i.e. until the
read() has returned. I guess if it didn't, it would make writing a
device driver harder, and it would almost certainly imply modifying all
existing device drivers to support threads.
If you really need a way to force the device closed regardless of what
is going on, I think ioctl() is the most sensible solution. Or maybe you
can just kill the thread?

-- 
Niels Diepeveen
Endea automatisering




More information about the Python-list mailing list