Question

I may not be looking hard enough but I am trying to replace a running python script with another python script. Based on the research that I have done, using the os.execl function may be what I am looking for. I am a little bit confused about the arguments that should be used with the function. Can anyone please help explain to me how to just replace the currently running python script with another.

Was it helpful?

Solution

exec*() familiy replaces the whole process, keeping the process number (PID). If this is what you want...

One example inside Python interpreter. I replace the interpreter by echo. The first item in 'args' becomes the argv[0] which is the process name that is seen in ps or top.

>>> import os
>>> args=['process_name', 'bla', 'ble']
>>> os.execlp("/bin/echo", *args)
bla ble
/Users/epx $ 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top