polling2
polling2 copied to clipboard
polling with function return
I want to poll the return value of a function:
def myfunction():
df=df_function()
global value
value=df[df['date']==date]
return True
polling2.poll(
lambda: myfunction == True,
step=30,
timeout=3600)
print(value)
But does not work: the polling script runs indefinitely.
Hi @frantz2501, sorry for the late reply. I didn't see this as I don't think github was setup to send me notifications correctly.
I assume you've already fixed your issue.
However, it looks like you are using the poll( method incorrectly. Your lambda function isn't going to work.
You have written, let me comment:
def myfunction():
df=df_function()
global value
value=df[df['date']==date]
return True # Are you sure you always want the last line to return true?
polling2.poll(
# There is no call to myfunction, you'd need to write 'myfunction() == True'
# But you don't need to do this. You can just pass the name of your function as the first parameter (the parameter target)
# and poll( will check it is true as the default
lambda: myfunction == True,
step=30,
timeout=3600)
print(value)
So I would write:
def myfunction():
df=df_function()
global value
value=df[df['date']==date]
return True
polling2.poll(
myfunction,
step=30,
timeout=3600)
print(value)