I want to write a process id to file whenever start my program, so I wrote this code, but this code write pid to file whenever stop the process.
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()
how to write pid to file in multiprocess?
UPDATE:
I use python 3.4 on windows 8.1