In my development, I have shared file which need to write mutliple process but I found it write only header part(only first line i.e test_data). I am able to create same behavior using following script. Any Input what am I missing?
#! /usr/bin/env python
import multiprocessing
def check_proc(procs):
"""checking cpu utilization befor starting process"""
for proc in procs:
proc.start()
while(len(multiprocessing.active_children())>10):
continue
for proc in procs:
proc.join()
while (len(multiprocessing.active_children())>5):
time.sleep(1)
def create_file():
f_data = open("temp", "w")
f_data.write("test data\n")
return f_data
def write_data(f_data, number, lock):
lock.acquire()
f_data.write(number)
lock.release()
def main():
f_data = create_file()
procs = []
lock = multiprocessing.Lock()
for i in range(0, 20, 1):
proc = multiprocessing.Process(target=write_data,
args=(f_data, str(i), lock))
procs.append(proc)
check_proc(procs)
if __name__ == "__main__":
main()
Expected: it should have number
Python2.7 and linux enviroment
I have gone through stack overflow question and block and found following link. But I am not able to relate or use in above code. Any input.
http://ptspts.blogspot.com/2013/08/how-to-send-unix-file-descriptors.html