polling2 icon indicating copy to clipboard operation
polling2 copied to clipboard

polling with function return

Open frantz2501 opened this issue 5 years ago • 1 comments

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.

frantz2501 avatar May 26 '20 10:05 frantz2501

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)

ddmee avatar Sep 11 '20 08:09 ddmee