# Threading and nodes limitations

**URL:** <https://forum.opencyphal.org/t/threading-and-nodes-limitations/1382>\
**Category:** PyCyphal\
**Created:** [July 29, 2021, 9:52pm UTC](https://forum.opencyphal.org/t/threading-and-nodes-limitations/1382 "2021-07-29T21:52:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LorenzoG](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@LorenzoG](https://forum.opencyphal.org/u/LorenzoG)\
**Post date:** [July 29, 2021, 9:52pm UTC](https://forum.opencyphal.org/t/threading-and-nodes-limitations/1382/1 "2021-07-29T21:52:36Z")

</div>

I’m using the legacy Python Library ‘uavcan’.

My setup: I’m connecting **two** CAN-Beds to a Raspberry-Pi that talk via SLCAN. One is ‘ttyACM0’ and the other ‘ttyACM1’

I have a Battery connected to one of the CAN-Beds.

I am able to spin a node and receive battery info. So far so good. Now since I’m building a GUI with PyQt I spin the node into its own QThread and still everything works.

Now, I want to scale my system to two nodes, each in its own QThread. This is where things don’t work anymore.

I connect the battery to both CAN-Beds.

I start each node and I’m expecting to receive data from both nodes but only **one** receives data. I know both are running because I put some print statements on the infinite loop that runs the spin method.

Something else that I noticed is that I get info for a second from one node and then it stops and the other node is now the only receiving. This is related to the order I start the nodes so maybe there is some resource that can’t be shared.

The only thing that occurs to me is that I’m doing something that wasn’t even supposed to be a use case of the library but

I don’t know enough to know what I don’t know.

Any insights on running parallel nodes are welcome!

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [July 30, 2021, 5:11am UTC](https://forum.opencyphal.org/t/threading-and-nodes-limitations/1382/2 "2021-07-30T05:11:08Z")

</div>

Are you sure this is not caused by Python’s GIL? Threading is kinda broken in Python.

---

<div class="post-metadata">

**Author:** ![LorenzoG](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/l/a183cd/32.png) [@LorenzoG](https://forum.opencyphal.org/u/LorenzoG)\
**Post date:** [August 2, 2021, 10:38pm UTC](https://forum.opencyphal.org/t/threading-and-nodes-limitations/1382/3 "2021-08-02T22:38:04Z")

</div>

So after a long session of debugging thru print statements. I found where things stop working. I cannot explain the cause because I stopped searching but in the **node.py** there is a method

```python
def call_handlers(self, transfer):
        for uavcan_type, wrapper in self._handlers:
            if uavcan_type == get_uavcan_data_type(transfer.payload):
                try:
                    wrapper(transfer)
                # noinspection PyBroadException
                except Exception as e:
                    logger.error("Transfer handler exception", exc_info=True)
                    if not self._catch_exceptions:
                        raise e

```

I know both my threads are running but one is never passing the check

```
      if uavcan_type == get_uavcan_data_type(transfer.payload):

```

So I printed `uavcan_type` and the value from `get_uavcan_data_type()` and if they were equal  
and saw this in the log

```auto
/dev/ttyACM2: 
uavcan_type = uavcan.equipment.power.BatteryInfo, 
get_uavcan_data_type() = uavcan.equipment.power.BatteryInfo
Are they equal: False

/dev/ttyACM1: 
uavcan_type = uavcan.equipment.power.BatteryInfo, 
get_uavcan_data_type() = uavcan.equipment.power.BatteryInfo
Are they equal: True

```

So I tried converting the values to strings before the comparison and now both threads are sending the data that I need.  
Too bad I can’t explain why is that ‘If’ failing when it shouldn’t.
