Human.io not stopping loop on_finished

20 views
Skip to first unread message

Joseph Mosby

unread,
Oct 6, 2012, 8:31:24 PM10/6/12
to humanio...@googlegroups.com
Human.io team,

I'm having some trouble with returning data out of a started loop. 

I'm trying to do this:

data = {this is a python data dictionary}

def func1(session, task, form_data):
# this is a function that works fine on its own

def func2(session, task, form_data):
# also works fine on its own

def on_finished(task):
task.app.stop_loop() 
 
def main():
task = app.create_task(description='My app', humans_per_item=1, on_connect_fn=on_connect, on_submit_fns={'func1':func1, 'func2', func2}, on_finished_fn=on_finished)
app.start_loop()

# then return data
return data 
 
I need to call the main function from an external script as follows:

import myhumaniofile
data = myhumaniofile.main()

Any thoughts?

Lawrence Kesteloot

unread,
Oct 6, 2012, 8:40:35 PM10/6/12
to humanio...@googlegroups.com
Your code seems fine. I assume you populate the global "data" variable from your functions? Is on_finished() not getting called?

Lawrence


--
You received this message because you are subscribed to the Google Groups "humanio-discuss" group.
To post to this group, send email to humanio...@googlegroups.com.
To unsubscribe from this group, send email to humanio-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/humanio-discuss/-/cVFZlVbDwYEJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Joseph Mosby

unread,
Oct 6, 2012, 8:54:20 PM10/6/12
to humanio...@googlegroups.com
Yes, data is just populated with values from the form fields. Having no issues when it's run as a standalone script, just when I try to call that main function from within another script. 

My understanding was that on_finished() was called automatically whenever the task had been completed enough times (i.e., if humans_per_item=3, on_finished() is called after session.dismiss() has been called 3 times). 

Should I be explicitly calling on_finished() somewhere or will it be automatically called by the loop?

Lawrence Kesteloot

unread,
Oct 6, 2012, 9:06:56 PM10/6/12
to humanio...@googlegroups.com
I don't see anything in your script that would cause it to work when you call main() from within that script but break when you call it from another script. What exactly happens when you try it?

Lawrence


To view this discussion on the web visit https://groups.google.com/d/msg/humanio-discuss/-/8LCiCx_iIgQJ.

Joseph Mosby

unread,
Oct 6, 2012, 9:45:20 PM10/6/12
to humanio...@googlegroups.com
So, I'll call the function from a Python shell as such:

data = myhumaniofile.main()

The form will pop up in the human.io web client, I'll plug in some dummy data, and hit submit. The form will exit as it should on the web client. However, when I wait for my function to finish executing in the shell, it just hangs. The script never terminates to allow me to further work with the data variable.

All this being said, this may be due to some weirder issues than just the script. I'm running this as a task in a Django/Python shell. It was previously being called as a Celery task (the source of the original issue). I tweaked the imports a bit so I could call the function directly, and now I'm getting a "Got 404 from server when registering the task" error that infinitely repeats in the console.

Lawrence Kesteloot

unread,
Oct 6, 2012, 10:28:07 PM10/6/12
to humanio...@googlegroups.com
Yeah sounds like there's something else going on. The "404" problem only comes up when you call register_task(), so you must be calling that repeatedly. I suggest you put "print" statements in all your callback functions to see which ones are really called. You can send me your code (feed...@tastylabs.com) if you want.

Lawrence


To view this discussion on the web visit https://groups.google.com/d/msg/humanio-discuss/-/vZQMXOXRnoUJ.
Reply all
Reply to author
Forward
0 new messages