question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't retrieve result in callback

See original GitHub issue

First of all - thank you for this wonderful library 😃

I’m trying to retrieve the result of a task from within a callback which does not work. My minimal setup:

# demo2.py

import time
import huey

huey_queue = huey.SqliteHuey(filename='demo2.db')

@huey_queue.signal(huey.signals.SIGNAL_COMPLETE)
def task_success(signal, task):
    print("----")
    print(task)
    print(signal)
    print(huey_queue.get(task.id))
    print("----")

@huey_queue.task()
def slow_task():
    time.sleep(3)
    return "OK"
# taskrunner2.py

from demo2 import slow_task

k1 = slow_task()
slow_task()

Terminal 1: huey_consumer.py demo2.huey_queue

Terminal 2: py taskrunner2.py

Output in terminal 1:

----
demo2.slow_task: 1c0a3cd7-2132-46c4-b37f-d1cf124dfcfd
complete
None
----

However when I open IDLE / ptpython or standard python prompt, I can import the huey_queue and retrieve the result:

from demo2 import huey_queue
res = huey_queue.get("1c0a3cd7-2132-46c4-b37f-d1cf124dfcfd")
print(res)
'OK'

Am I doing something wrong or is it not possible to retrieve the result within the callback? I tried adding a delay in the callback before retrieving the results but it made no difference.

Win10 Python3.7.3 huey 2.1.2

/EDIT removed unnecessary line

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
coleifercommented, Oct 16, 2019

Pushed 2.1.3

0reactions
sometimescool22commented, Oct 16, 2019

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't return data from callback function at NodeJS
console.log(s); will execute immediately after assigning function to var s , and function returns the value after the find query, so the inital ......
Read more >
How to access the correct this inside a callback
We explore the methods for accessing the correct this in a callback by explicitly forcing a context binding to point to our object...
Read more >
Callback Hell
Callback Hell. A guide to writing asynchronous JavaScript programs. What is "callback hell"? Asynchronous JavaScript, or JavaScript that uses callbacks, ...
Read more >
How to retrieve value returned by a callback function? - Reddit
You can't. Use a callback to return the value. Or you can use promises, along with fs.promises .
Read more >
How to return the result of an asynchronous function in ...
Find out how to return the result of an asynchronous function, promise based or callback based, using JavaScript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found