So I have an issue with the import of a driver, which apparently leads to almost all threads that I open to end in a Resourcewarning. (python version 3.9.16 on Windows in Anaconda environment; nidaqmx version 0.6.5)
After opening and closing multiple instances of threads with the import, the Kernel appears to die.
Here is the minimal reproducible example:
import threading
import nidaqmx #This is the import that causes the problems
def idling():
for i in range(10):
print("still idling")
When I now try to run the idling method in a thread:
idling_thread = threading.Thread(target = idling)
idling_thread.start()
I can reproduce the warning message
sys:1: ResourceWarning: unclosed socket <zmq.Socket(zmq.PUSH) at 0x132d0955880>
I already tried finding the socket that is unclosed using tracemalloc, which showed me the following:
File "C:\Users\lib\site-packages\ipykernel\iostream.py", lineno 563
self._schedule_flush()
File "C:\Users\lib\site-packages\ipykernel\iostream.py", lineno 469
self.pub_thread.schedule(_schedule_in_thread)
File "C:\Users\lib\site-packages\ipykernel\iostream.py", lineno 210
self._event_pipe.send(b"")
File "C:\Users\lib\site-packages\ipykernel\iostream.py", lineno 98
event_pipe = ctx.socket(zmq.PUSH)
File "C:\Users\lib\site-packages\zmq\sugar\context.py", lineno 259
s: ST = self._socket_class( # set PYTHONTRACEMALLOC=2 to get the calling frame
So it seems to me as if the underlying cause is, that the import of the driver somehow messes up the communication with my thread. I could just ignore this warning, but as mentioned before, I noticed, that consecutively opening and closing the camera thread (usually around 4 times) leads to the Kernel dying and restarting.
Please note, that without the import of the driver nidaqmx, all threads work fine. With the nidaqmx driver imported, the threads work fine, up to the point where they would close.
I would be very happy if anyone has an idea how to fix the underlying problem.