Skip to content

Commit

Permalink
[eclipse-kanto#98] Ensure graceful exit of the quickstart Python scri…
Browse files Browse the repository at this point in the history
…pt and the How-to guide Python scripts

Fixed the issue in all scripts

Signed-off-by: Daniel Milchev <[email protected]>
  • Loading branch information
daniel-milchev committed Sep 2, 2022
1 parent 903bd54 commit 0c10276
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions quickstart/hono_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def on_message(self, event):
print('[ok]', command)
else:
print('[error]')
event.receiver.close()
event.connection.close()

def on_connection_closed(self, event):
print('[closing]')
os.kill(os.getpid(), signal.SIGINT)


Expand Down
19 changes: 15 additions & 4 deletions quickstart/hono_commands_fu.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ def on_message(self, event):
print('[ok]', "fu")
else:
print('[error]')
os.kill(os.getpid(), signal.SIGINT)
event.receiver.close()
event.connection.close()

def on_connection_closed(self, event):
print('[closing]')
os.kill(os.getpid(), signal.SIGINT)


class CommandsInvoker(MessagingHandler):
Expand Down Expand Up @@ -88,7 +93,7 @@ def on_sendable(self, event):
value=value)
print(payload)
msg = Message(body=payload, address='{}/{}'.format(self.address, device_id), content_type="application/json",
subject="fu", reply_to=reply_to_address, correlation_id=correlation_id, id=str(uuid.uuid4()))
subject=self.action, reply_to=reply_to_address, correlation_id=correlation_id, id=str(uuid.uuid4()))
event.sender.send(msg)
event.sender.close()
event.connection.close()
Expand Down Expand Up @@ -121,10 +126,16 @@ def on_message(self, event):
print(json.dumps(body, indent=2))
if body["value"]["state"] == "SUCCESS":
print('[successful upload]')
os.kill(os.getpid(), signal.SIGINT)
event.receiver.close()
event.connection.close()
elif body["value"]["state"] == "FAILED":
print('[failed upload]')
os.kill(os.getpid(), signal.SIGINT)
event.receiver.close()
event.connection.close()

def on_connection_closed(self, event):
print('[closing]')
os.kill(os.getpid(), signal.SIGINT)


# Parse command line args
Expand Down
6 changes: 6 additions & 0 deletions quickstart/hono_commands_su.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ def on_message(self, event):
print('[ok]', "su")
else:
print('[error]')
event.receiver.close()
event.connection.close()

def on_connection_closed(self, event):
print('[closing]')
os.kill(os.getpid(), signal.SIGINT)



class CommandsInvoker(MessagingHandler):
def __init__(self, server, address):
super(CommandsInvoker, self).__init__()
Expand Down

0 comments on commit 0c10276

Please sign in to comment.