Stepper interface : python program crashes when USB is unplugged

Comments & issues
Supporting Windows 8 or newer
Post Reply
shogun
Fresh meat
Posts: 4
Joined: Tue Apr 15, 2025 10:48 am
Contact:

Stepper interface : python program crashes when USB is unplugged

Post by shogun »

Hello,
first post, I'm using a stepper motor with a 4A stepper interface, in windows, under Python.
Everything runs as expected, motor operates well but I have one problem : if I disconnect the USB interface while the program is running, it crashes with a recursive mutex error.


Enclosed here is a my setup, a simple sample code and output (The disconnect event is registered):


Setup :
-------
General
Python 3.12.8
OS : Windows 10

Library :
Name: phidget22
Version: 1.22.20250106

Stepper interface :
DeviceName: 4A Stepper Phidget
DeviceVersion: 110

Hub interface
Connected to :
Hub: HUB0002 (6-Port USB VINT Hub Phidget) v101


Sample code :
-------------

Code: Select all


from Phidget22.Phidget import *
from Phidget22.Devices.Stepper import *


class mot_class:
    def __init__(self, parent=None):
        self.info = ""
        self.info2 = ""
        self.status = 0 

    def init(self):
        if self.status == 0:
            try:
                self.motor = Stepper()
                self.motor.openWaitForAttachment(5000)
                self.motor.setOnDetachHandler(self.onDetachMotor)
                self.motor.setOnAttachHandler(self.onAttachMotor)        
                self.motor.open()
                self.info="I/F connected"
                self.status = 1              

            except PhidgetException  as e:
                return

    def onAttachMotor(self,info):
        self.info = "I/F reconnected"
        self.info2 = info
        self.status = 1 
        
    def onDetachMotor(self,info):
        self.info = "I/F disconnected"
        self.info2 = info
        self.status = 0

if __name__ == "__main__":
    mot=mot_class()
    mot.init()
    while 1:
       print(str(mot.info) + " - " +str(mot.info2))
	   


Output :
--------
(program is running and you pull the USB plug)
I/F connected -
I/F connected -
I/F connected -
I/F connected -
I/F disconnected - PhidgetStepper
I/F disconnected - PhidgetStepper
lock 00000001802D48C0 failed: recursive mutex enter
I/F disconnected - PhidgetStepper
recursive mutex
I/F disconnected - PhidgetStepper
(returns to prompt)

Note: I also have a force interface (bridge), and this one you can attach and reattach without problem.

Any help would be appreciated.
Sincerely,
Anthony.

Note : edited for insertion of code tags.
User avatar
Patrick
Lead Developer
Posts: 666
Joined: Mon Jun 20, 2005 8:46 am
Location: Calgary
Contact:

Re: Stepper interface : python program crashes when USB is unplugged

Post by Patrick »

Hi,

I can't reproduce your issue. Can you enable library logging and post the output?

Code: Select all

Log.enable(LogLevel.PHIDGET_LOG_INFO, "logfile.log")
Also, it's an error to call open on a channel multiple times, though it shouldn't cause issues. And you would normally register event handler before calling open.

You may also want to try the latest libraries and see if the problems persists.

-Patrick
shogun
Fresh meat
Posts: 4
Joined: Tue Apr 15, 2025 10:48 am
Contact:

Re: Stepper interface : python program crashes when USB is unplugged

Post by shogun »

Hello Patrick,
thanks for investigating.
So I ran the code with logging and here is the attached logfile.
(note : I removed second open and so no more already open warning)
Yours sincerely,
Anthony.
Attachments
phidgetlog.log
(2.4 KiB) Downloaded 17 times
User avatar
Patrick
Lead Developer
Posts: 666
Joined: Mon Jun 20, 2005 8:46 am
Location: Calgary
Contact:

Re: Stepper interface : python program crashes when USB is unplugged

Post by Patrick »

Hi,

I believe this error has been fixed as of the 1.22.20250324 release - can you try updating your libraries?

-Patrick
shogun
Fresh meat
Posts: 4
Joined: Tue Apr 15, 2025 10:48 am
Contact:

Re: Stepper interface : python program crashes when USB is unplugged

Post by shogun »

Patrick,
thanks for the feedback,

unfortunately, I had already upgraded the Phidgets22 install to the latest (see screenshot).

The Version: 1.22.20250106 was referring to the Python API, which is already the latest version (checked with pip and on your site)

I will try a linux computer for comparison when I get the time, and keep you posted.

Sincerely,
Anthony.
Attachments
version.PNG
version.PNG (20.99 KiB) Viewed 1430 times
User avatar
Patrick
Lead Developer
Posts: 666
Joined: Mon Jun 20, 2005 8:46 am
Location: Calgary
Contact:

Re: Stepper interface : python program crashes when USB is unplugged

Post by Patrick »

Hi,

It looks like the python library got missed for the 1.22.20250324 release. I have pushed a release just now. The pip package includes it's own copy of the native library, and you can see what version is being run from the logfile. Let me know if that fixes the issue.

-Patrick
shogun
Fresh meat
Posts: 4
Joined: Tue Apr 15, 2025 10:48 am
Contact:

Re: Stepper interface : python program crashes when USB is unplugged

Post by shogun »

Hi Patrick, I did the pip upgrade and... it works !!!
I can now disconnect then reconnect.
Congratulations and thank you for your effort, much appreciated !
Yours sincerely,
Anthony.
Post Reply