Avoid a crash in some conditions when reading the serial console

This commit is contained in:
Julien Duponchelle 2017-02-15 19:31:38 +01:00
parent 897c9cb42c
commit 10b039074f
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

View File

@ -34,6 +34,7 @@ class SerialReaderWriterProtocol(asyncio.Protocol):
def __init__(self): def __init__(self):
self._output = asyncio.StreamReader() self._output = asyncio.StreamReader()
self._closed = False
self.transport = None self.transport = None
def read(self, n=-1): def read(self, n=-1):
@ -54,9 +55,11 @@ class SerialReaderWriterProtocol(asyncio.Protocol):
self.transport = transport self.transport = transport
def data_received(self, data): def data_received(self, data):
self._output.feed_data(data) if not self._closed:
self._output.feed_data(data)
def close(self): def close(self):
self._closed = True
self._output.feed_eof() self._output.feed_eof()