PyCharm: Execute an external process before Run/Debug and run it in parallel
I need to run an external process (not a Python script, let's say an executable or batch) before Run/Debug is started but don't wait until it's finished (as "Before launch" tasks work) rather start the Python script to be Run/Debugged in parallel and when it's finished it may be terminated or just left running.
Imagine I need to run a server or another process which is communicating with my Ran/Debugged Python script so it has to be already running when the Python script is executed and I don't want to start it manually every time. Actually, I would need to run more such processes (servers) in parallel.
When I add those server processes to a Run/Debug configuration as the "Before launch" tasks, PyCharm is executing them sequentially one by one, waiting with starting another one until the previous one is finished. The Python script is only run after the last "Before launch" task is finished.
Is it possible in PyCharm Comunity or with any plugin, please?
请先登录再写评论。
Hello Dawid,
> When I add those server processes to a Run/Debug configuration as the "Before launch" tasks, PyCharm is executing them sequentially one by one, waiting with starting another one until the previous one is finished. The Python script is only run after the last "Before launch" task is finished.
Do you use "External Tool" option in "Before launch" section? So adding an external tool to "Before launch" section of your run configuration won't work in the way you described because that's how "Before launch" section works: tools launched from run configuration need to return an exit code - the main process is waiting for return code to start. This is the way "Before launch" is designed - it's supposed to be used to run some sort of pre-processing before running the main process.
Please vote for the related feature requests https://youtrack.jetbrains.com/issue/IDEA-113525 to increase its priority and be notified about updates.
You could also take a look at custom Multirun plugin (https://plugins.jetbrains.com/plugin/7248?pr=idea) to see if it helps.
Hi Anna,
thank you for your answer. My point wasn't to complain about how the "Before launch" tools work but rather to find out if there's any way to achieve what I need.
Thanks for the feature request ticket that's exactly what I need so I have upvoted it.
I have tried the Multirun plugin before with no success but I have tried to set it up once more and even though it's not ideal, it seems to be doing what I need. My setup is the following:
But still, I would prefer to have such feature in PyCharm itself. The current solution, for example, doesn't allow me to set any start up delay for a particular configuration or to set up when and how (e.g. kill or send Ctrl + C) a configuration should be stopped.
Check out Compound run/debug configurations.
I for example can run a Django project, also add a Shell Script to run after Django Server. In my case, I'm running Redis, then Celery from two shell scripts.
For some unknown reason, you can't control moving the compound configurations up or down in the list (in my PyCharm version anyways). That would be the most ideal to control the order in which each configuration gets executed. Maybe it 's a bug or something.