Skip to content

TypeError: int() can't convert non-string with explicit base terminates watcher thread #4

Description

@user202729

Sometimes I think what happens is the other thread gets permission denied (searching around for the error message with serial package) and stops:

Exception in thread Thread-8:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "X/plover_auto_reconnect_machine/plover_auto_reconnect_machine.py", line 43, in run
    if isinstance(self._engine._machine, SerialStenotypeBase) and not self._port_exists(self._engine._machine.serial_params['port']):
  File "X/plover_auto_reconnect_machine/plover_auto_reconnect_machine.py", line 65, in _port_exists
    for port in list_ports.comports():
  File "X/.local/lib/python3.9/site-packages/serial/tools/list_ports_linux.py", line 100, in comports
    for info in [SysFS(d) for d in devices]
  File "X/.local/lib/python3.9/site-packages/serial/tools/list_ports_linux.py", line 100, in <listcomp>
    for info in [SysFS(d) for d in devices]
  File "X/.local/lib/python3.9/site-packages/serial/tools/list_ports_linux.py", line 51, in __init__
    self.vid = int(self.read_line(self.usb_device_path, 'idVendor'), 16)
TypeError: int() can't convert non-string with explicit base

Possible fix (before the serial package is fixed: add a try-except in _port_exists check.

diff --git a/plover_auto_reconnect_machine.py b/plover_auto_reconnect_machine.py
index d67805f..3cc57e2 100644
--- a/plover_auto_reconnect_machine.py
+++ b/plover_auto_reconnect_machine.py
@@ -62,7 +62,10 @@ class AutoReconnectMachine:
             self._lock.notify()

     def _port_exists(self, portName):
-        for port in list_ports.comports():
-            if port.device == portName:
-                return True
+        try:
+            for port in list_ports.comports():
+                if port.device == portName:
+                    return True
+        except:
+            pass
         return False

I think something like this would work, if looks good to you.

(this issue isn't easy to reproduce, will comment more in a few days.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions