Replace running python script with os.execl

Maybe I'm not looking hard enough, but I'm trying to replace the running python script with another python script. Based on the research that I did, using the os.execl function might be what I'm looking for. I am a little confused by the arguments that should be used with this function. Can someone please explain to me how easy it is to replace the current python script with another.

+3
source share
1 answer

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

One example inside the Python interpreter. I am replacing the interpreter with an echo. The first element in 'args' becomes argv [0], which is the name of the process that maps to ps or top.

>>> import os
>>> args=['process_name', 'bla', 'ble']
>>> os.execlp("/bin/echo", *args)
bla ble
/Users/epx $ 
+1
source

All Articles