generators not working
ALL software version info
Software Version Info
python 3.11.9
param 2.2.0
Description of expected behavior and the observed behavior
should print g
Complete, minimal, self-contained example code that reproduces the issue
def g():
while True: yield 'g'
import param
class P(param.Parameterized):
p = param.String(allow_refs=True)
p = P(p=g)
#print(next(g()))
print(p.p) # nothing prints
I can reproduce this. It works a bit better in a notebook, if the last line is executed in another cell.
This doesn't seem like a bug to me, the generator has to get scheduled on a thread so it doesn't block things on the main thread so if you print immediately after running it, it won't have time to run and yield a value.
This doesn't seem like a bug to me, the generator has to get scheduled on a thread so it doesn't block things on the main thread so if you print immediately after running it, it won't have time to run and yield a value.
sigh. that would not be expected behavior.
This doesn't seem like a bug to me, the generator has to get scheduled on a thread so it doesn't block things on the main thread so if you print immediately after running it, it won't have time to run and yield a value.
Ok indeed that's at least documented there https://param.holoviz.org/user_guide/Generators.html#asynchronous-generators. I also find that surprising to be honest.
There's really no alternative, a generator like this:
def g():
while True: yield 'g'
would simply block forever.
Maybe we should start with your use case, what would be expected behavior for you here? Yielding from the generator once, yielding from it every time the parameter is accessed, yielding from it when a class is instantiated?
Maybe we should start with your use case, what would be expected behavior for you here? Yielding from the generator once, yielding from it every time the parameter is accessed, yielding from it when a class is instantiated?
I was expecting the getting behavior to simply like calling next on the generator : on access and on inst. Perhaps param should deal with functions (as blocking) and generators (as non-blocking).