pyepics / newportxps

python support code for NewportXPS drivers
BSD 2-Clause "Simplified" License
20 stars 17 forks source link

Don't reinitialize global variables when creating an XPS object #20

Closed dennisjlee closed 1 month ago

dennisjlee commented 1 month ago

This allows creating multiple NewportXPS objects in one process and accessing them from different threads (each with their own unique socket and XPS object).

dennisjlee commented 1 month ago

My use case was to create three NewportXPS instances and access them from different threads:

When I initially tried this without my patch, each time I made a NewportXPS object, it would create an XPS, which would reset XPS.__nbSockets and XPS.__usedSockets, so each NewportXPS object would have _sid == 0 and would end up trying to communicate using the same socket.

With this patch, the three NewportXPS objects get _sid = 0, _sid = 1, _sid = 2 as expected, and they can all communicate successfully using separate sockets.

newville commented 1 month ago

@dennisjlee Thanks! I'm sort of surprised that I never hit this before ;).