Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a running python script with os.execl

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.

like image 252
user3286192 Avatar asked Oct 01 '22 15:10

user3286192


1 Answers

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 $ 
like image 132
epx Avatar answered Oct 05 '22 12:10

epx