I'm trying to import `mymodule.py` in the constructor of C class in order each new instance of the C class to use its own mymodule when the `f` method is called as a new process using multiprocessing module.

Please review the code below:

**mymodule.py**

```
import random
n = random.randint(0, 1000)

```

**mp\_test.py**

```
import time
import multiprocessing as mp
import imp

class C(object):

    def __init__(self, c='*'):
        self.mm=imp.load_module('mm', *imp.find_module('mymodule'))
        self.c = c

    def f(self):
        print self.c, id(self.mm), id(self.mm.n), self.mm.n

def main():

    p = []
    for _ in range(2):
        p.append(mp.Process(target=C().f))
        p[-1].start()

    time.sleep(1)
    print ''

    p0 = mp.Process(target=C(c='>').f)
    p1 = mp.Process(target=C(c='>').f)
    p0.start()
    p1.start()

if __name__ == '__main__':
    main()

```

After the execution of the `mp_test.py` the stdout result is:

```
funk@linux:~/mp_test# python mp_test.py
* 140679674677800 94828316092856 40
* 140679674677800 94828316835224 486

> 140679674677800 94828317211688 763
> 140679674677800 94828317211688 763

```

As expected the following piece of code creates to different instances of `mymodule` and consequently two different random numbers are generated:

```
    p = []
    for _ in range(2):
        p.append(mp.Process(target=C().f))
        p[-1].start()

* 140679674677800 94828316092856 40
* 140679674677800 94828316835224 486

```

When the `start()` methods are called as follows `mymodule` is not imported twice and consequently the random numbers are the same...

```
    p0 = mp.Process(target=C(c='>').f)
    p1 = mp.Process(target=C(c='>').f)
    p0.start()
    p1.start()

> 140679674677800 94828317211688 763
> 140679674677800 94828317211688 763

```

Your ideas please...!

**Edit**

zwer's [suggestion](https://stackoverflow.com/a/51083991/2194843) resolves the issue:

**Code correction**

```
    # ERROR self.mm=imp.load_module('mm', *imp.find_module('mymodule'))
    self.mm=imp.load_module('mm_' + str(uuid.uuid4()), *imp.find_module('mymodule'))

```

**Updated results**

```
funk@linux:~/mp_test# python -O mp_test.py
* 139813126327944 94540189500648 396
* 139813126447184 94540189500504 491

> 139813126447296 94540189500432 847
> 139813126447240 94540189500384 389

```

**Note** that the 1st column of the latest results that represents the `id(self.mm)` is always different!