pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.32k stars 365 forks source link

Prefix command run in backgroup #836

Open albatros69 opened 2 years ago

albatros69 commented 2 years ago

Hello, I have a use case for invoke for which I can't figure out a clean solution: I need to launch a process in the background, run my main task, and then kill the background process. In a standard CLI, I simply do:

$ background_process &
$ main_task
$ kill %1

Ideally, I'd like to do this with an invoke context:

c = invoke.context.Context()
with c.background_prefix('background_process'):
    c.run('main_task')

Would this be already possible? If no, could this be a possible new feature?