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

task.add_done_callback does not work on task.current_task #144

Closed
dlashua opened this issue Jan 13, 2021 · 0 comments
Closed

task.add_done_callback does not work on task.current_task #144

dlashua opened this issue Jan 13, 2021 · 0 comments

Comments

@dlashua
Copy link
Contributor

dlashua commented Jan 13, 2021

@time_trigger('startup')
def startup():
    log.info('starting')
    my_task = task.current_task()
    task.add_done_callback(my_task, all_done)
    task.sleep(5)

def all_done():
    log.info('task has ended')

The above code results in the following error:

2021-01-13 06:19:48 ERROR (MainThread) [custom_components.pyscript.scripts.test.uniq2.startup] Exception in <scripts.test.uniq2.startup> line 7:
        task.add_done_callback(my_task, all_done)
                                        ^
KeyError: <Task pending name='Task-6896361' coro=<Function.run_coro() running at /config/custom_components/pyscript/function.py:419>>
Traceback (most recent call last):
  File "/config/custom_components/pyscript/eval.py", line 827, in aeval
    val = await getattr(self, name, self.ast_not_implemented)(arg)
  File "/config/custom_components/pyscript/eval.py", line 1757, in ast_call
    return await self.call_func(func, func_name, *args, **kwargs)
  File "/config/custom_components/pyscript/eval.py", line 1787, in call_func
    return await func(*args, **kwargs)
  File "/config/custom_components/pyscript/trigger.py", line 178, in user_task_add_done_callback
    Function.task_add_done_callback(task, ast_ctx, callback, *args, **kwargs)
  File "/config/custom_components/pyscript/function.py", line 472, in task_add_done_callback
    cls.task2cb[task]["cb"][callback] = [ast_ctx, args, kwargs]
KeyError: <Task pending name='Task-6896361' coro=<Function.run_coro() running at /config/custom_components/pyscript/function.py:419>>
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

No branches or pull requests

1 participant