Pre-condition:
Using py2exe tool chains to transfer .py to .exe.
Issue:
The .exe process cannot be stopped automatically when closed, which keeps occupying resources (CANcase in my case) and cannot be available for another exception.
Solutions:
The root cause is that, I have a thread to use the hardware, which can be cancelled within Python environment, but things goes wrong when transferred to .exe.
So I have to cancel this thread by myself in the code, by calling thread.setDaemon(True) before thread.run(). and it can stop the thread as soon as main thread is killed.