Closed goretkin closed 1 year ago
what if you have 2 different tasks running in different threads?
@schettino72 , I am not sure I understand. Is that an argument against doing any process-wide state changes, like changing the current directory, within a task?
Is that an argument against doing any process-wide state changes, like changing the current directory, within a task?
yes. of course you could do this on your own code on your own risk. but doit
will not support that.
so what then, is the standard way of operating in a subdirectory of the root (which has dodo.py).
E.g. I want to do a docker compose build
in my deployment subdirectory. Manually, from the root, this is:
cd ./deployment
docker compose build
I'm sure I could do it without the cd using docker command-line args, but many similar tasks are neater when working from a specific cwd. What's the doit way of operating in a subdir? (I've scoured the docs for cd, directory, chdir, and can't find much here)
What's the doit way of operating in a subdir?
None. You should use python's standard way of manipulating the current working directory. Just note that it is not thread safe, so you might have problems if executing tasks in parallel.
If you explicitly use CmdAction
(not just pass a string) you could use the subprocess.Popen
's cwd
parameter.
Running the
dodo.py
below:Gives the following output:
What if the tasks themselves took care of restoring the working directory, since
doit
relies on it?Upvote & Fund