0

I have a parent python script which makes a subprocess call to another python script using Popen 10 times with diff arguments. I want this second script to make changes to a list declared in parent python script.

Right now I am doing:

   p = [Popen("python child.py "+str(i),shell=True) for i in range(10)]
   for i in p:
       i.wait()

While this solves my purpose, now if I have a list declared before the Popen line and I want to access this list in child.py, how do I do it? I considered using pickle library but opening and closing a file for 10 times(as child.py is called 10 times) will just increase my I/O time which is not desirable.

human torch
  • 303
  • 5
  • 15
  • This was already asked... http://stackoverflow.com/questions/1268252/python-possible-to-share-in-memory-data-between-2-separate-processes – Rainer Feb 05 '16 at 10:14
  • I could not quite understand that. I'm sorry. – human torch Feb 05 '16 at 10:21
  • Just have a look at os.fork(). Depending on your exact requirements it could solve your problem. But all that is pretty crazy. Couldn't solve a simple database your problem as well? Even file based databases are caching stuff so it would not necessary cause more I/O traffic. – Rainer Feb 05 '16 at 10:28
  • there are multiple answers possible (different IPC methods, different Python implementations of the same methods). Ask a more specific question (if you need to improve performance then you should start with a simple working code, make sure it is correct (test), measure its time performance, and set a goal (e.g., to "run it 10 times faster than a simple implementation on your hardware") otherwise there are too many answers possible. – jfs Feb 13 '16 at 14:46

0 Answers0