KVS Python Binding Example¶
Description: Use the KVS Python interface to store user data into KVS¶
If you haven’t already, download the files and change your working directory:
$ git clone https://github.com/flux-framework/flux-workflow-examples.git $ cd flux-workflow-examples/kvs-python-bindings
Launch a Flux instance by running
flux start, redirecting log messages to the file
outin the current directory:
flux start -s 1 -o,-S,log-filename=out
Submit the Python script:
flux mini submit -N 1 -n 1 ./kvsput-usrdata.py
Attach to the job and view output:
flux job attach 6705031151616
hello world hello world again
Each job is run within a KVS namespace.
FLUX_KVS_NAMESPACEis set, which is automatically read and used by the KVS operations in the handle. To take a look at the job’s KVS, convert its job ID to KVS:
flux job id --from=dec --to=kvs 6705031151616
The keys for this job will be put at the root of the namespace, which is mounted under “guest”. To get the value stored under the first key “usrdata”:
flux kvs get job.0000.0619.2300.0000.guest.usrdata
Get the value stored under the second key “usrdata2”:
flux kvs get job.0000.0619.2300.0000.guest.usrdata2
"hello world again"
f = flux.Flux()creates a new Flux handle which can be used to connect to and interact with a Flux instance.
kvs.put()places the value of udata under the key “usrdata”. Once the key-value pair is put, the change must be committed with
kvs.commit(). The value can then be retrieved with
kvs.get()on a directory will return a KVSDir object which supports the
withguarantees a commit is called on the directory.