[PyQT] QSocketNotifier problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Axel Mittendorf

    [PyQT] QSocketNotifier problem

    Hi, I have a pyqt app which reads data from a fifo ( created with mkfifo)
    and displays it
    in a text field. I use PyQT 3.8.1 and QT 3.2.2 on SuSE Linux 7.0. I open the
    fifo with os.open and create a QSocketNotifier (for reading). Other
    processes write into
    the fifo (I can do 'echo "hello" > /tmp/myfifo' for example), the activated
    event of the QSocketNotifier comes and the data is written out. This
    works without problems. BUT when the last process that writes into that
    fifo exits, the activated event seems to come "always", about 10000 times
    per second. What causes this behavior?

    Is it a bad idea to use a SocketNotifier for a fifo?
    BTW I used a QTimer before but I was ordered to use a SocketNotifier
    instead (not my idea;-).

    TIA, Axel


  • Jeff Epler

    #2
    Re: [PyQT] QSocketNotifier problem

    I suspect that QSocketNotifier is built on top of poll or select. The
    documentation I have for poll is too terse for me to be sure, but I
    suspect POLLIN behaves like the readfs set in select. The documentation
    for select makes it clear that "readable" means that reading will not
    block---so an end-of-file condition counts.

    I'm not sure how you're really supposed to deal with this in a way that
    doesn't block, doesn't spin, and doesn't involve doing something based
    off a timer. Here's one idea that does involve a timer:

    When reading the FIFO indicates an end-of-file condition, close the
    fifo. Then, at intervals, attempt to reopen it. When opened with
    O_NONBLOCK, the open fails with ENXIO if there is no writer.

    Ensuring that there's always a writer for the FIFO might work too,
    because then poll/select will not detect an end-of-file condition.

    Jeff

    Comment

    Working...