Skip to content

Commit

Permalink
fix child process catching
Browse files Browse the repository at this point in the history
  • Loading branch information
maltfield committed Jul 27, 2024
1 parent 748325b commit 2749938
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/buskill_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ def toggle_buskill(self):
# buskill failed to arm/disarm; tell the user

msg = "Unable to toggle buskill state"
# TODO: why is 'e' not defined?
#msg += "\n\n" +str(e)
msg += "\n\nException: " +str(self.bk.usb_handler.exception[0])
# for some reason 'e' is undefined, but we can get the exception thrown
# by the child process from its 'exception' instance field
if self.bk.usb_handler.exception[0]:
msg += "\n\nException: " +str(self.bk.usb_handler.exception[0])

print( msg )
self.dialog = DialogConfirmation(
title = '[font=mdicons][size=30]\ue002[/size][/font] Error',
Expand Down
18 changes: 1 addition & 17 deletions src/packages/buskill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,34 +1007,21 @@ def toggle(self):

# launch an asynchronous child process that'll loop and listen for
# usb events
msg = "DEBUG: 0"; print( msg ); logger.error( msg ) # TODO: remove me
self.usb_handler = self.Process(
target = self.ARM_FUNCTION
)
msg = "DEBUG: 1"; print( msg ); logger.error( msg ) # TODO: remove me
self.usb_handler.start()
msg = "DEBUG: 2"; print( msg ); logger.error( msg ) # TODO: remove me

# did we arm successfully?
start = time.time()
msg = "DEBUG: 3"; print( msg ); logger.error( msg ) # TODO: remove me
while True:
# don't update the UI until the child process either sends us a
# 'ping' or throws an exception
msg = "DEBUG: 4"; print( msg ); logger.error( msg ) # TODO: remove me

self.check_usb_handler(0)
msg = "DEBUG: 5"; print( msg ); logger.error( msg ) # TODO: remove me

# TODO: remove prints
msg = "usb_handler._exception:|" +str(self.usb_handler._exception)+ "|"; print(msg); logger.debug(msg)
msg = "usb_handler.exception:|" +str(self.usb_handler.exception)+ "|"; print(msg); logger.debug(msg)
msg = "DEBUG: 6"; print( msg ); logger.error( msg ) # TODO: remove me
msg = "usb_handler.status:|" +str(self.usb_handler.status)+ "|"; print(msg); logger.debug(msg)
msg = "DEBUG: 7"; print( msg ); logger.error( msg ) # TODO: remove me

# did the child process throw an exception?
if self.usb_handler._exception:
if self.usb_handler.exception:
# the child process threw an exception; raise it now

msg = "ERROR: child process throw exception:" +str(e)
Expand Down Expand Up @@ -1151,9 +1138,6 @@ def simulate_hotplug_removal( self ):
# this works for both linux and mac
def armNix( self ):

# TODO remove me (exception catching testing)
#raise Exception( 'this is a test exception' )

# are we just simulating this USB removal?
if self.SIMULATE_HOTPLUG_REMOVAL:
# we're simulating a removal event
Expand Down

0 comments on commit 2749938

Please sign in to comment.