How to get around the need for multiple twisted reactors

I am running a Qt application on Linux using qt4reactor. The application sends and receives bytes on the serial port. This works very well on Linux with QtReactor.

However, when I port the application to Windows, I have a problem. On Windows, I use the SerialPort class from _win32SerialPort. The doc line in _win32SerialPort is pretty clear:

  Requires PySerial and win32all, and needs to be used with win32eventreactor.

I assume that the use of win32eventreactor is due to the fact that addReader, addWriter methods are created for windows.

When using QtReactor, once the lostConnection function is called on the transport, it calls lostConnection in twisted.internet.abstract, which ultimately calls the qt4reactor addwriter method (to clear the output).

Then qt4reactor.TwistedSocketNotifier is created, which tries to get the file descriptor number for select (). The abstract.fileno method is not overwritten by _win32SerialPort, so -1 is always returned, and I get

  QSocketNotifier: Invalid Socket specified

I saw a lot of posts about several reactors that are not allowed in a twisted state, but I think I'm right to suggest that I need QtReactor for a Qt application and win32eventreactor for a Windows serial port.

Or is there another workaround that I can use?

NOTE 1: when using QtReactor in windows, serial ports work fine, that is, they can send and receive data. Only when I close the application do I get an "Invalid socket"

Note 2: Now I have found a workaround. I use QtReactor, but when I close my application I do

  serial.connectionLost (failure.Failure (Exception))

where serial is an instance of _win32serialport.SerialPort

Therefore, abstract.loseConnection is never called, which means the QtReactor addWriter application is never called to clear the output. I suspect, however, that a better solution involves calling lostConnection and correctly allocating output.

+4
source share
2 answers

I recently added a serial port supported by selectreactor, iocpreactor and gtkreactor on Windows . I think this approach can be expanded to support them in the Qt reactor.

+2
source

Call the Qt message verification / processing functions in an unoccupied case in the Win32 reactor.

0
source

All Articles