Executing doit repeatedly, delayedTasks are only executed once(?)

21 views
Skip to first unread message

Holger Bruch

unread,
Jan 20, 2021, 12:19:59 PM1/20/21
to python-doit
I'm trying to run doit via a schedule every n seconds. However, a delayed task is only executed for the first time. How could I reset doit to recreate the task on each run?

Thx, Holger

Example:

run_doit_in_loop.py:

import schedule
import time
from doit.doit_cmd import DoitMain

def run_doit():
    print("run doit")
    DoitMain().run("")

schedule.every(1).seconds.do(run_doit)

while True:
    schedule.run_pending()
    time.sleep(1)

dodo.py:
from doit import create_after

def task_a():
return {'actions': ['echo a']}

@create_after(executed='a')
def task_b():
return {'actions': ['echo b']}

Output:
run doit
.  a
.  b
run doit
.  a
run doit
.  a
...


Eduardo Schettino

unread,
Jan 20, 2021, 12:58:15 PM1/20/21
to python-doit
Hi,

It is a bug. Normally doit is not executed repeatedly in the same process. Might need more fixes...

The "create_after" decorator attaches some info to the function object and it is also used to track the task creation.
Following diff fixes it:

Can you please create an issue on github so this dont get lost.

diff --git a/doit/loader.py b/doit/loader.py
index 5b7f256..76ec8af 100644
--- a/doit/loader.py
+++ b/doit/loader.py
@@ -2,6 +2,7 @@
 
 import os
 import sys
+import copy
 import inspect
 import importlib
 from collections import OrderedDict
@@ -137,7 +138,7 @@ def load_tasks(namespace, command_names=(), allow_delayed=False):
     def _process_gen():
         task_list.extend(generate_tasks(name, ref(), ref.__doc__))
     def _add_delayed(tname):
-        task_list.append(Task(tname, None, loader=delayed,
+        task_list.append(Task(tname, None, loader=copy.copy(delayed),
                               doc=delayed.creator.__doc__))
 
     for name, ref, _ in funcs:


--
You received this message because you are subscribed to the Google Groups "python-doit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-doit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-doit/e400d093-d8f9-4086-ac67-93fbf1f3e0fbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages