How to run some clean up code after all the tasks been executed?

19 views
Skip to first unread message

GeorgeX

unread,
Aug 23, 2019, 6:05:45 PM8/23/19
to python-doit
Suppose that I have to create an client for some tasks, and it can be very expensive to create the client. After the execution of all the tasks, the `client` better to be closed. but I haven't find a way to do that. 

Eduardo Schettino

unread,
Aug 23, 2019, 6:08:45 PM8/23/19
to python-doit

On Sat, Aug 24, 2019 at 6:05 AM GeorgeX <georg...@gmail.com> wrote:
Suppose that I have to create an client for some tasks, and it can be very expensive to create the client. After the execution of all the tasks, the `client` better to be closed. but I haven't find a way to do that. 

--
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/a96812ed-b63a-47d7-9852-0b4576fa8103%40googlegroups.com.

GeorgeX

unread,
Aug 23, 2019, 11:47:00 PM8/23/19
to python-doit
I found the "teardown" keyword. but it looks like it will run for each task/sub-task. 

tried the following code: 

 with get_some_expensive_client(**) as some_client:
        DoitMain(ModuleTaskLoader({
            'task_xyz': func_xyz
        })).run(sys.argv[1:])

It seems working, but the issue is that the client is kind of a global variable. Is there a way for the task function to take an argument? then the `client` can be passed in to the task. 

GeorgeX

unread,
Aug 24, 2019, 5:51:22 PM8/24/19
to python-doit
Never mind. There is some simple work around. Thanks for the nice tool: doit! 
Reply all
Reply to author
Forward
0 new messages