0

Here's my code:

from multiprocessing import Process, freeze_support
import time

freeze_support()


print("Importing plotly ten times ...")

def f():
   import plotly

print("Before: {}.".format(time.strftime('%H:%M:%S')))

for i in range(10):
   p= Process(target=f)
   p.start()
   p.join()

print("After:  {}.".format(time.strftime('%H:%M:%S')))


print("Importing matplotlib ten times ...")

def f():
   import matplotlib

print("Before: {}.".format(time.strftime('%H:%M:%S')))

for i in range(10):
   p= Process(target=f)
   p.start()
   p.join()

print("After:  {}.".format(time.strftime('%H:%M:%S')))

When I try to run this, with or without the call to freeze_support, I get the following error:

RuntimeError:
Attempt to start a new process before the current process
has finished its bootstrapping phase.

This probably means that you are on Windows and you have
forgotten to use the proper idiom in the main module:

...

The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce a Windows executable.

Any advice will be appreciated.

Phillip M. Feldman
  • 468
  • 1
  • 7
  • 17
  • 1
    Are you running on Windows? Did you try the suggestion in the error message about "proper idiom in the main module"? – bnaecker Feb 10 '20 at 04:07
  • The last sentence tells the reader they did try to use `freeze_support` – TankorSmash Feb 10 '20 at 04:09
  • On Windows, your executable code needs to be in a `if __name__ == "__main__":` block as stated in the error message you received. – tdelaney Feb 10 '20 at 04:09
  • With everything after initial 2 lines enclosed in the `if __name__ == "__main__", I get a different error message: AttributeError: Can't get attribute 'f' on Also, it is deeply perplexing to me that the `if __name__ == "__main__"` test makes any difference. As I understand it, the purpose of this test is to differentiate between the case where the module is being imported and the case where it is running as a script. Where the module only runs as a script, it seems as though the `if __name__ == "__main__"` should be superfluous. – Phillip M. Feldman Feb 10 '20 at 21:45

0 Answers0