DEMCON / libstored

Generator for a store--a set of variables--to be embedded in an application, with fast store access via C++ and VHDL, data synchronization between processes, and remote access for the Embedded Debugger.
https://demcon.github.io/libstored
Mozilla Public License 2.0
10 stars 2 forks source link

`libstored.wrapper.serial` must always be killed #54

Closed RobertoRoos closed 1 year ago

RobertoRoos commented 1 year ago

Running the serial wrapper on Windows always causes an exception when trying to shut it down (sending a KeyboardInterrupt):

Exception in thread Thread-3 (_forwardStream):
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python310\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Name\project\extern\libstored\python\libstored\zmq_server.py", line 86, in _forwardStream
    data = r()
  File "C:\Users\Name\project\extern\libstored\python\libstored\zmq_server.py", line 77, in <lambda>
    r = lambda: stream.readline().encode()
  File "C:\Program Files\Python310\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

The process always has to be killed in order to progress.

I'm running it as:

python -m libstored.wrapper.serial -S segment,arq,crc16,ascii,pubterm COM4 1000000
RobertoRoos commented 1 year ago

Had a look with @jhrutgers - this issue is specific to running the script from the PyCharm IDE. The PyCharm runner is adding something to the stdin, which is received and throws an error in the wrapper.

EDIT: This can also be avoided by checking "Emulate terminal in output console" the PyCharm run configuration.

jhrutgers commented 1 year ago

We could improve the shutdown behavior in case of such an error, but just silently dropping Unicode errors as you propose in the PR, is not the solution. Apparently, there is something wrong with the I/O (hence the exception), but that should either be solved automatically, or lead to some proper error report with shutdown. As this seems to be an issue with the environment (PyCharm), I would suggest the latter.