Skip to content

shutdown trigger with task.unique() fails #117

Closed
@dlashua

Description

@dlashua

I've finally managed to get this boiled down and reproduceable.

  1. Install this code in a script:
@time_trigger('startup')
def test_startup():
    task.unique('test_counter')
    log.info('starting')
    cnt = 0
    while True:
        cnt += 1
        log.info(f'count {cnt}')
        task.sleep(1)

@time_trigger('shutdown')
def test_shutdown():
    task.unique('test_counter')
    log.info('stopping')
  1. pyscript.reload to make it active. See it counting.
  2. save the file again to update mtime. pyscript.reload. See it counting again.
  3. repeat step 3 one more time. See the error below in logs.
2020-12-13 06:29:01 INFO (MainThread) [custom_components.pyscript.global_ctx] Reloaded /config/pyscript/shutdowntest.py
2020-12-13 06:29:01 INFO (MainThread) [custom_components.pyscript.file.shutdowntest.test_shutdown] stopping
2020-12-13 06:29:01 INFO (MainThread) [custom_components.pyscript.file.shutdowntest.test_startup] starting
2020-12-13 06:29:01 INFO (MainThread) [custom_components.pyscript.file.shutdowntest.test_startup] count 1
2020-12-13 06:29:01 ERROR (MainThread) [custom_components.pyscript.function] task_reaper: got exception Traceback (most recent call last):
  File "/config/custom_components/pyscript/function.py", line 97, in task_reaper
    await cmd[1]
RuntimeError: await wasn't used with future

2020-12-13 06:29:02 INFO (MainThread) [custom_components.pyscript.file.shutdowntest.test_startup] count 2

Once this error is produced, while the counter itself keeps counting, many other pyscript scripts stop triggering reliably as they usually do.

  1. Repeat step 3 again and you will now see there are two counters. The previous one didn't stop, but a new one started.
  2. Do it again and you now have three counters. etc, etc.
  3. To fix it, comment out the script added in step 1 and restart home assistant. (without restarting home assistant and just doing pyscript.reload, only the most recent counter is stopped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions