christoph2 / pyxcp

ASAM XCP in Python
http://pyxcp.rtfd.org
GNU Lesser General Public License v3.0
207 stars 64 forks source link

fix trying to restart threads when connecting multiple times #148

Closed toebsen closed 11 months ago

toebsen commented 11 months ago

When trying to connect e.g. via UDP to a XCP slave which is not responding, the default error handler will try to reconnect infinite times. In some scenarios this is not sensible. Therefore, I've disabled the error handler.

This unfortunately leads to a RuntimeError: threads can only be started once from self._packet_listener.start() in the transport.connect()

I've fixed this for all the relevant transports, but only verified that it works with the ethernet transport. Possible repro script:

import threading
import time

import pyxcp

master = pyxcp.Master("eth",
                      config={
                          "HOST": "127.0.0.1",
                          "PROTOCOL": "UDP",
                          "DISABLE_ERROR_HANDLING": True,
                          "LOGLEVEL": "DEBUG"
                      })

for _ in range(5):
    try:
        master.connect()
    except pyxcp.types.XcpTimeoutError as exc:
        print(exc)

With the proposed changes it is possible to call the connect multiple times, when the error handler is disabled.

Types of changes

christoph2 commented 11 months ago

OK, looks good -- I think the other transports are not affected of this pesky problem.

toebsen commented 11 months ago

@christoph2 Thanks for merging. It seems that the deploy to pypi failed: https://github.com/christoph2/pyxcp/actions/runs/6509156789/job/17680708294. Can you please take a look?

christoph2 commented 11 months ago

OK, now available as 0.21.6 on PyPI. The small problem is/was the lack of documentation -- If you submit a PR bumpversion patch is required, otherwise the upload_pypi action is faced with an already existing version on PyPI and fails. I'm currently working on a larger update, hopefully including documentation (definitely including high-level measurement functions)...