Can't retrieve result in callback
See original GitHub issueIssue Description
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:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Pushed 2.1.3
Thanks!