Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout param, only tested in demo so far #52

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Feb 7, 2025

Fixes #54

Obviously this needs an integration test, but I wanted to just get implementation structure now. It is functional, tested with the demo script.

ERROR:dispatcher.worker.task:Worker 1 task canceled (uuid=1db13c11-a50a-4b0a-91c7-8cbc401c7436)
Traceback (most recent call last):
  File "/home/arominge/repos/dispatcher/dispatcher/worker/task.py", line 84, in run_callable
    return _call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/arominge/repos/dispatcher/tools/test_methods.py", line 28, in task_has_timeout
    time.sleep(5)
  File "/home/arominge/repos/dispatcher/dispatcher/worker/task.py", line 31, in task_cancel
    raise DispatcherCancel
dispatcher.worker.task.DispatcherCancel
DEBUG:dispatcher.pool:Worker 1 finished task (uuid=1db13c11-a50a-4b0a-91c7-8cbc401c7436), ct=16, expected cancel, canceled

There are some aesthetic changes we could make, like call it "timeout" instead of "cancel"... but obviously timeout uses the same mechanism as cancel. Maybe I'll just rename the exception to DispatcherInterrupt or something like that.

Also, I'm relatively happy with the structure, although it took some thought. I implemented "delayed" task in the "main" part of the code. It's non-obvious that timeouts will go in the pool part, but the pool can gate on capacity, and timeouts don't start until the worker actually starts running it. And this is definitely something we want enforced in the parent, in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a task timeout
1 participant