Changing the process name of python script in windows

You have created several python scripts and running them simultaneously. You decide you want to kill the first script you run. As always, you open Windows Task Manager but then you see several python.exe processes. Which one is the script you want to kill? You do not have a clue. If you recognize this situation – The following script I wrote allows overcoming this issue and change name of python processes to unique one.

Overview

The idea is basically based on the fact that Windows Task Manager displays the image name of the process (the name of the binary file which is executed by the process). If we copy the python.exe to a unique name and then running it, we will see the newly copied image name in Windows Task Manager. Since this file is a copy python.exe, we can invoke it as usual to execute any python script.

The script

Create a new file named python-by-name.bat in the python directory with the following contents:

python-by-name.bat
 set PYTHON_HOME=%~dp0
 set PYTHON_NAME=%1.exe
 copy "%PYTHON_HOME%python.exe" "%PYTHON_HOME%%PYTHON_NAME%"
 set args=%*
 set args=%args:* =%
 "%PYTHON_HOME%%PYTHON_NAME%" %args%

Usage

Now, Let's see how we can use this above batch to distinguish between your python scripts.

Suppose you want to run the following command:

 python 
Invoke the following command instead:
 python-by-name my_unique_name 
Now, my_unique_name.exe process will appear in Windows Task Manager instead of python.exe.