May this help?
test.py:(just for demo)
import time, os, datetime, fcntl
with open("output.txt", "a") as g:
fcntl.flock(g, fcntl.LOCK_EX)
g.write( "PID [" + str(os.getpid()) + "]," + str(datetime.datetime.now()) + "\n" )
fcntl.flock(g, fcntl.LOCK_UN)
time.sleep(30)
with open("output.txt", "a") as g:
fcntl.flock(g, fcntl.LOCK_EX)
g.write( "PID [" + str(os.getpid()) + "]," + str(datetime.datetime.now()) + "\n" )
fcntl.flock(g, fcntl.LOCK_UN)
Run it several times:
c@chen:~/src$ python test2.py &
[1] 29265
c@chen:~/src$ python test2.py &
[2] 29266
c@chen:~/src$ python test2.py &
[3] 29268
c@chen:~/src$ python test2.py &
[4] 29269
c@chen:~/src$ vim test2.py
[1] Done python test2.py
[2] Done python test2.py
[3]- Done python test2.py
[4]+ Done python test2.py
Output:
c@chen:~/src$ tail -f -n 100 output.txt
PID [29265],2016-01-20 16:28:20.373244
PID [29266],2016-01-20 16:28:21.068946
PID [29268],2016-01-20 16:28:21.911043
PID [29269],2016-01-20 16:28:22.547805
PID [29265],2016-01-20 16:28:50.403474
PID [29266],2016-01-20 16:28:51.075268
PID [29268],2016-01-20 16:28:51.914001
PID [29269],2016-01-20 16:28:52.564706
multiprocessing.Processno option?