Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure graceful exit of the quickstart Python script and the How-to guide Python scripts #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('[connection closed]')
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('[connection closed]')
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('[connection closed]')
os.kill(os.getpid(), signal.SIGINT)


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

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


Expand Down