0

I have a code which looks like following:

import some_module
def foo(f):
  //do something
  some_module.func()

jobs = [mp.Process(target=foo, args=(f,)) for f in files]

for job in jobs:
    job.start()

for job in jobs:
    job.join()

So, each process spawned has its own copy of foo function but all the processes try to access the same copy of the function some_module.func() My requirement is that each process have separate copy of foo and some_module.func() so that one process does not hinder progress of another process.

Aman Gupta
  • 3,627
  • 4
  • 40
  • 64
  • And what's your question exactly ? – bruno desthuilliers Mar 30 '15 at 07:34
  • The processes which are spawned are using the same copy of 'some_module.func()'. For example, suppose 'some_module.func()' is creating an instance of webdriver, so what is happening that all process are using same webdriver instance instead of creating there own instances. It means all processes are accessing same copy of 'some_module.func()' . Hope that clears a bit. – Aman Gupta Mar 30 '15 at 07:44
  • I think you will need to give more detail, and an example that demonstrates your point. No process shares the same modules or functions with any other process. Separate processes only share memory unless specifically requested (by using the classes provided by multiprocessing). – Dunes Mar 30 '15 at 09:07
  • Ok. I will post my original code that may give a better insight. – Aman Gupta Mar 30 '15 at 09:13
  • 1
    Modules are singletones in python. Instead of calling "some_module.func()" you should consider defining a class inside "some_module" which when instantiated within the "foo" function will provide the "func" function. – Mr. Girgitt Mar 30 '15 at 09:20
  • http://stackoverflow.com/questions/10936709/why-does-a-python-module-act-like-a-singleton , I guess it'll tell you something. – pnv Mar 30 '15 at 09:33

0 Answers0