Huey will block indefinitely if task returns None
See original GitHub issueIssue Description
I have a task that returns None. If I do a blocking call on the result r(blocking=True)
it will wait indefinitely. Can huey distinguish between None, and a result not being ready?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Getting Started — huey 1.11.0 documentation - Read the Docs
To disable result storage, you can either return None or specify result_store=False when initializing your Huey instance.
Read more >Huey task not running from django view but works from shell
Huey task is not running when called from web view. But when called from shell command from same VM it runs fine. The...
Read more >API Documentation — peewee 3.15.4 documentation
Transactions and save-points can be explicitly committed or rolled-back within the wrapped block. If this occurs, a new transaction or savepoint is begun...
Read more >Is this the right way to write a Task that loop indefinitely? : r/swift
Line 45 doesn't block the thread. It just suspends your task, which is exactly what you want.
Read more >Switching a Python Scheduler to Huey Task Queue ... - YouTube
https://mikelev.in/blog/switching-a-python-scheduler-to- huey - task -queue-using-crontab-api/I switch pip install schedule to pip install huey, ...
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
Why are you blocking on the result of a task that returns none? Just return a dummy value.
The reason huey does not store
None
by default is to allow the user to run tasks without filling up the result store with garbage. A result is only removed the result store when it is read. Otherwise there is no “clean-up” process.Recommendation:
store_none=True
- unless you are periodically cleaning out your results store or you are sure to resolve every result.This is a design decision of huey. Huey store the results of tasks, which then have to be read in order to be removed from result storage. Because many (most?) users just fire off tasks without resolving the result (e.g., send an email, check if comment is spam, generate thumbnails, etc), we don’t want to fill up the result-store with meaningless results that never get checked (e.g., a million
None
values for all the tasks you’ve ever executed).The only other way to handle this would be to force tasks to return a sentinel value, and just ignoring None by default seems much more sane to me.
For the case where you do want to block on a result, then the result needs to be non-None - since None is ignored by default and not put in the result-store in the first place. I think it is better to just return
True
or something in the case where you want to block, rather than default to storing results for every task – even the ones that do not have a meaningful return value. Huey allows you to do this, though, it’s just not the default – for what I think are obvious reasons.Because you’re blocking on resolving the result.
If you want you can also just add an “on-complete” signal handler instead, depending on your use-case (which isn’t tied to the result store).
https://huey.readthedocs.io/en/latest/signals.html