Flux python-api kvs issue #5199
-
Hi all, After playing around with kvs from the commandline:
Then if I run the line:
And if I run: This all works great! However, using the python API: If I run:
I get the following error:
Am I misunderstanding the python API - or is this a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
Hi, I believe the python KVS API is quite out of the date for what the KVS is today. In the past, I believe all KVS data was stored in JSON, thus the Could you explain your use case? Perhaps we need to determine a short term "make it work for now" fix or up the priority on actually making the python KVS API more functional than its older legacy state. Or if you can do what you need with the other API calls, perhaps it should be removed to remove future accidental usage. (For issue linking, noted in #5037). Edit: Sorry, I clicked submit before I was finished writing, hopefully you see the updated text here :-) Edit2: For my own personal debugging, the |
Beta Was this translation helpful? Give feedback.
-
We are looking to have something like a master flux process and submitted flux jobs add items to the KVS (or another non-filesystem-based store) that we can get out from the master process to allocate more resources/jobs where needed. Is this something that can be done from the python "job" interface? edit: Thank you so much for the quick response!. |
Beta Was this translation helpful? Give feedback.
-
ok, lemme look to see if I can do something to the current api to make it work again. I'm actually wondering if the |
Beta Was this translation helpful? Give feedback.
-
For the time being you may be able to monkeypatch in a fixed version of import flux
from flux import kvs
from _flux._core import ffi, lib
from flux.wrapper import Wrapper
RAW = Wrapper(ffi, lib, prefixes=["flux_kvs", "flux_kvs_"])
def kvs_get(handle, key):
valp = ffi.new("char *[1]")
future = RAW.flux_kvs_lookup(handle, None, 0, key)
RAW.flux_kvs_lookup_get(future, valp)
if valp[0] == ffi.NULL:
return None
result = ffi.string(valp[0]).decode("utf-8")
RAW.flux_future_destroy(future)
return result
flux.kvs.get_key_direct = kvs_get
handle = flux.Flux()
d = flux.kvs.KVSDir(handle)
print(d["a"]["b"]["c"]) $ flux kvs put a.b.c="test"
$ flux python t.py
test |
Beta Was this translation helpful? Give feedback.
-
Playing around, I also thought of a very stupid workaround. Since import flux
import flux.kvs
f = flux.Flux()
d = flux.kvs.KVSDir(f)
print(d['a']['b']['c'])
|
Beta Was this translation helpful? Give feedback.
-
Thanks Mark and Al, at least for the time being I think this should work for us - I think we could represent pretty much any python object/datatype as strings so this SHOULD already let us write and read nearly any datatype to KVS. |
Beta Was this translation helpful? Give feedback.
-
Also, as an aside, the following are the same: print(d['a']['b']['c'])
print(d['a.b.c']) IMO, the latter is preferred, just because that's what you'd do on the command line like |
Beta Was this translation helpful? Give feedback.
-
hopefully no one objects, I'm going to move this into discussions and leave #5198 as the issue for fixing. |
Beta Was this translation helpful? Give feedback.
Playing around, I also thought of a very stupid workaround. Since
json
is expected, could just quote the string. It's stupid and only works for this specific case, not the general case depending on what data you want to actually put in the KVS.