simetenn / uncertainpy

Uncertainpy: a Python toolbox for uncertainty quantification and sensitivity analysis, tailored towards computational neuroscience.
http://uncertainpy.readthedocs.io
GNU General Public License v3.0
220 stars 50 forks source link

AttributeError: 'MultiprocessLoggingHandler' #25

Closed tzipperle closed 5 years ago

tzipperle commented 5 years ago

I have installed with pip the version 1.1.0 of uncertainpy. I use Windows 10 and Python 3.6. When I tried the package I got the following error:

RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Users\gu\AppData\Local\Continuum\anaconda3\envs\uncertainty\lib\logging\__init__.py", line 1945, in shutdown
    h.close()
  File "C:\Users\gu\AppData\Local\Continuum\anaconda3\envs\uncertainty\lib\site-packages\uncertainpy\utils\logger.py", line 141, in close
    if not self.is_closed:
AttributeError: 'MultiprocessLoggingHandler' object has no attribute 'is_closed'

@simetenn Do you have any idea what's wrong?

simetenn commented 5 years ago

Yes, this seems to be a problem with the combination of Windows and multiprocessing. The solutions seems to be to add everything in your script inside of an if __name__ == '__main__': block. Unfortunately, I do not have a windows machine available to test this on.

See https://docs.python.org/2/library/multiprocessing.html#windows, as well as https://stackoverflow.com/questions/18204782/runtimeerror-on-windows-trying-python-multiprocessing.

tzipperle commented 5 years ago

Thanks for the hint. With the if __name__ == '__main__': statement the package works under windows.