@@ -1026,22 +1026,28 @@ def timer_handler():
1026
1026
delayed_halt .start ()
1027
1027
# Keep transferring data to and from the device until one of the endpoints
1028
1028
# is halted.
1029
- while delayed_halt .is_alive ():
1030
- if ctrl_error .is_set ():
1031
- raise_unconditionally (lineno (), 'Halting endpoint {0.bEndpointAddress:#04x} failed'
1032
- .format (ep_to_halt ))
1033
- try :
1034
- loopback_ep_test (ep_out , ep_in , ep_out .wMaxPacketSize )
1035
- except usb .core .USBError as err :
1029
+ try :
1030
+ while delayed_halt .is_alive ():
1031
+ if ctrl_error .is_set ():
1032
+ raise_unconditionally (lineno (), 'Halting endpoint {0.bEndpointAddress:#04x} failed'
1033
+ .format (ep_to_halt ))
1036
1034
try :
1037
- ep_status = usb . control . get_status ( dev , ep_to_halt )
1035
+ loopback_ep_test ( ep_out , ep_in , ep_out . wMaxPacketSize )
1038
1036
except usb .core .USBError as err :
1039
- raise_unconditionally (lineno (), 'Unable to get endpoint status ({!r}).' .format (err ))
1040
- if ep_status == 1 :
1041
- # OK, got USBError because of endpoint halt
1042
- return
1043
- else :
1044
- raise_unconditionally (lineno (), 'Unexpected error ({!r}).' .format (err ))
1037
+ try :
1038
+ ep_status = usb .control .get_status (dev , ep_to_halt )
1039
+ except usb .core .USBError as err :
1040
+ raise_unconditionally (lineno (), 'Unable to get endpoint status ({!r}).' .format (err ))
1041
+ if ep_status == 1 :
1042
+ # OK, got USBError because of endpoint halt
1043
+ return
1044
+ else :
1045
+ raise_unconditionally (lineno (), 'Unexpected error ({!r}).' .format (err ))
1046
+ except :
1047
+ raise
1048
+ finally :
1049
+ # Always wait for the Timer thread created above.
1050
+ delayed_halt .join ()
1045
1051
raise_unconditionally (lineno (), 'Halting endpoint {0.bEndpointAddress:#04x}'
1046
1052
' during transmission did not raise USBError.'
1047
1053
.format (ep_to_halt ))
0 commit comments