考虑以下另存为的脚本test.py
:
from sys import argv, executable
from os import execl
print(argv)
if argv[1] == 'a':
argv[1] = 'b'
print('execl')
execl(executable, 'process_name', *argv)
print('the interpreter will never get to this line!')
下面是运行脚本的结果:
$ python3 test.py a
['test.py', 'a']
execl
['test.py', 'b']
我很好奇会发生什么'process_name'
?新的 python 进程是否将它存储在某个地方以便可以读取?
我试过psutil.Process(os.getpid()).name()
了,但它'python.exe'
两次都返回。