flux.core.handle module

class flux.core.handle.Flux(url=_flux._core.ffi.NULL, flags=0, handle=None)

Bases: Wrapper

The general Flux handle class, create one of these to connect to the nearest enclosing flux instance

Example

>>> flux.Flux()
<flux.core.Flux object at 0x...>
add_watcher(watcher)

Add a reference to a watcher so it avoids garbage collection

attr_get(attr_name)
barrier(name, nprocs)
close()

The underlying flux handle is automatically closed when a Flux instance is deconstructed. Prevent users from manually closing, the handle, leading to a double free.

del_watcher(watcher)

Remove ref to watcher so it is eligible for garbage collection

event_create(topic, payload=None)

Create a new event message.

Parameters
  • topic -- A string, the event's topic

  • payload -- If a string, the payload is used unmodified, if it is another type json.dumps() is used to stringify it

event_recv(topic=None)
event_send(topic, payload=None)

Create and send a new event in one step

event_subscribe(topic)

Subscribe to events

Parameters

topic (str, bytes, or unicode) -- The event's topic to subscribe to

Raises
  • EnvironmentError -- if the topic is None or NULL

  • TypeError -- if the topic is not a str, bytes, or unicode

fd_watcher_create(fd_int, callback, events=None, args=None)
get_rank()
in_reactor()
log(level, fstring)

Log to the flux logging facility

Parameters
  • level -- A syslog log-level, check the syslog module for possible values

  • fstring -- A string to log, C-style formatting is not supported

msg_watcher_create(callback, type_mask=<bound method Wrapper.__getattr__.<locals>.wrap_class of <flux.core.inner.Core object>>, topic_glob='*', args=None, match_tag=<bound method Wrapper.__getattr__.<locals>.wrap_class of <flux.core.inner.Core object>>, rolemask=None)
classmethod raise_if_exception()

Re-raise any class global exception if set

If a global exception is currently set for the Flux handle class, re-raise it and reset the exception state to None.

The exception is raised from None to preserve the original stack trace.

reactor_decref(reactor=None)
classmethod reactor_enter()
classmethod reactor_exit()
reactor_incref(reactor=None)
reactor_run(reactor=None, flags=0)

Run reactor associated with this Flux handle or reactor argument if it is provided. Sets a signal watcher for SIGINT to return from the reactor on Ctrl-C, and raise KeyboardInterrupt.

classmethod reactor_running()

Return True if this thread is running the Flux reactor

reactor_stop(reactor=None)
reactor_stop_error(reactor=None)
recv(type_mask=<bound method ? of <flux.core.inner.Core object>>, match_tag=<bound method ? of <flux.core.inner.Core object>>, topic_glob=None, flags=0)

Receive a message, returns a flux.Message containing the result or None

respond(message, payload=None)

Respond to a flux rpc

Parameters
  • message (Message) -- The message to respond to

  • payload (None, str, bytes, unicode, or json-serializable) -- The (optional) payload to include in the response

rpc(topic, payload=None, nodeid=<bound method ? of <flux.core.inner.Core object>>, flags=0)

Create a new RPC object

send(message, flags=0)

Send a pre-constructed flux message

service_register(name)
service_unregister(name)
classmethod set_exception(exception)

Set a global, per-thread exception for Flux

This class method allows Python callbacks called from the Flux reactor to set a global exception which can be re-thrown after the return to Python (when reactor_run() returns). This is implemented as a class attribute since the Flux handle object which is available in a Python callback from C will be a different instantiation than the Flux handle object which started the reactor (with the same underlying flux_t however)

Parameters

exception (Exception) -- A reference to the exception thrown.

Returns

The previously set exception, or None

Return type

Exception

signal_watcher_create(signum, callback, args=None)
timer_watcher_create(after, callback, repeat=0.0, args=None)
tls = <_thread._local object>