我想在每次启动程序时向文件写入进程id,所以我写了这段代码,但这段代码在进程停止时就将pid写入文件。在
from multiprocessing import Process
from os import getpid
def f():
file = open('udp.pid', 'w')
file.write(str(getpid()))
file.close()
while True:
# a socket infinity loop
pass
if __name__ == '__main__':
p = Process(target=f,)
p.start()
如何在多进程中将pid写入文件?在
更新:
我在Windows8.1上使用Python3.4
我认为是否使用多进程并不重要。只是为了写作!在
打开(name[,mode[,buffering]])
在https://docs.python.org/2/library/functions.html
更改您的代码
到
^{pr2}$相关问题 更多 >
编程相关推荐