Serialport connection lost not handled.

[email protected] Sat, 30 Jan 2010 19:49:22 -0000
Newsgroups gmane.comp.python.twisted.bugs
Message-ID <[email protected]>
New submission from mdamen <None>:

When you disconnect a device connected to the serial port, twisted reports an unhandled error. Here is the traceback:

{{{
Traceback (most recent call last):
  File "C:\Python26\Lib\site-packages\twisted\python\log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "C:\Python26\Lib\site-packages\twisted\python\log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "C:\Python26\Lib\site-packages\twisted\python\context.py", line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "C:\Python26\Lib\site-packages\twisted\python\context.py", line 37, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "C:\Python26\Lib\site-packages\twisted\internet\win32eventreactor.py", line 211, in _runAction
    closed = getattr(fd, action)()
  File "C:\Python26\Lib\site-packages\twisted\internet\_win32serialport.py", line 68, in serialReadEvent
    n = win32file.GetOverlappedResult(self._serial.hComPort, self._overlappedRead, 0)
pywintypes.error: (995, 'GetOverlappedResult', 'The I/O operation has been aborted because of either a thread exit or an application request.')
}}}

There should be some kind of error handling to prevent this, I had a look at it but can't figure out what should be done. Here's a basic example to reproduce the problem:

{{{
from twisted.internet import protocol
from twisted.internet.serialport import SerialPort
from sys import platform
if platform == 'win32':
    from twisted.internet import win32eventreactor
    win32eventreactor.install()
from twisted.internet import reactor

class TestProto(protocol.Protocol):
    def connectionMade(self):
        print "connection made"
        
    def connectionLost(self):
        print "connection lost"

SerialPort(TestProto(),2, reactor, '115200')        
reactor.run()
}}}

----------
Type     : defect
Component: core
Keywords : 
Priority : normal
Nosy     : 
----------
http://twistedmatrix.com/trac/ticket/4249