Skip to content

How to handle event messages asynchronously in Python? #6383

Answered by grondo
grondo asked this question in Q&A
Discussion options

You must be logged in to vote

To handle event messages in Flux, you first have to subscribe to the event topic of interest with handle.event_subscribe. Then create a message watcher for the EVENT type message with handle.msg_watcher_create(). Finally start the message handler, then enter the reactor.

Here's a simple example that subscribes to heartbeat.pulse and calls a callback for each event:

import flux
  
#  Message handler callback:
#  Args:
#   handle: Flux handle on which the msg was receieved
#   msg_handler: this message handler
#   msg: the message
#   arg, arbitrary argument passed to args parameter of msg_watcher_create()
#
def hb_cb(handle, msg_handler, msg, arg):
    print(f"got {msg.topic}")

handle = flux

Replies: 1 comment 1 reply

Comment options

grondo
Oct 22, 2024
Maintainer Author

You must be logged in to vote
1 reply
@vsoch
Comment options

Answer selected by grondo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants