Skip to content

Improve Python scripts used by examples with graceful shutdown #772

@bnouwt

Description

@bnouwt

With the following code we can make sure docker containers which run Python scripts shut down more graceful and delete their KB before exiting. This ensures that the rest of the network immediately gets a notification that the KB is gone and therefore update their state. Otherwise, you need to wait about 1 minute before the whole network is aware that a particular KB is gone.

import signal

...
"""
Make sure that this Python program handles SIGTERM by raising a
KeyboardInterrupt, to end the program.
"""
def handle_sigterm(*args):
    raise KeyboardInterrupt()

signal.signal(signal.SIGTERM, handle_sigterm)


...

try:
    kb.start_handle_loop()
except KeyboardInterrupt:
    log.info("Gracefull shutdown requested...")
finally:
    kb.unregister()

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions