1

module path lost in multiprocessing spawn (ModuleNotFoundError)

The so-called solution of inserting sys-path above the importing of the module does not work for me.

Here is my main.py

import multiprocessing
from testing import customfunction

customfunction(1,2,3)
if __name__ == "__main__":
    process = multiprocessing.Process(target=customfunction)
    process.start()
    process.join()
    print("DONE")

The main.py works fine up to process.start()

This means customfunction has been imported properly

Here is my testing.py

import random

def customfunction(size, test, hello):
    random.seed(size)
    print(random.random())
    return random.random()

Both main.py and testing.py are in the same folder. A separate folder with an init.py file did not work as well.

I get this error:

   from testing import customfunction
ModuleNotFoundError: No module named 'testing'

I can not wrap my head around why does the process created not retain the system pathing in order to import the file. If i place the multiprocessing creation in customfunction it doesn't work either, the same error occurs.

The link I shared at the top does not work for me as well.

Thank you for taking the time to read. If you believe this is a duplicate of another question, please link it and explain, I am new to python.

EDIT:

I am using Windows 10 as my OS

I have installed Spyder 4.1.4 using Anaconda Navigator, Python 3.7.7. I installed using a executable package.

I have tested this code on VS Code as well.

I am running this via the two IDEs mentioned(E.G VS Code Powershell console and Spyder's Python Console by clicking run)

I generally currently believe it is an issue specific to my computer, and I'll like to know if its replicable in other Windows Systems and whether or not the linked "solution" in the first line works. With that I may be able to pinpoint my errors

UberChio
  • 11
  • 5

2 Answers2

0

This should work if you invoke multiprocessing.Process(target=customfunction, args=(1,2,3)) instead. I can't think of a reason why this would not work on Linux.

Can you update your question and provide the following information?

  • What OS are you using?
  • What version of Python are you running, and how was it installed?
  • How are you running main.py (e.g. from the command line, from an IDE, etc.)?
  • Any other details about your system configuration that might help others answer your question?
  • Hey there, thanks for replying. I have updated the question to include the information requested. I am glad to see that this sort of code should work on Linux, as this means that it may be a computer specific problem rather than a library problem. – UberChio Nov 19 '20 at 01:41
0

No multiprocessing print outputs (Spyder)

The solution mentioned here seems to solve my problem, I never expected either VS Code or Spyder's Console to have an issue with multiprocessing, but running the code in an external system terminal works.

Thank you to Melih Elibol for helping me think more clearly about the problem, I am new to python.

UberChio
  • 11
  • 5