- Python3.7 使用时报错
- wandb
- Login
- dataloader
- RuntimeError: freeze_support()
- 全局变量:
urllib.error.URLError:
Solution1
将以下block copy至要跑的代码前。
import urllib.request
import ssl
def main():
ssl._create_default_https_context = ssl._create_unverified_context
response = urllib.request.urlopen('https://www.python.org')
Your codes start here......
Solution2
conda install -c anaconda certifiwandb Login
每个新项目都要login一次wandb,在https://wandb.ai/ 找到API 直接填入terminal,例如:
wandb login 123abc42623e2649730766b922bb71f40effbcc6dataloader RuntimeError: freeze_support()
BrokenPipeError: [Errno 32] Broken pipe
File “xxxxpython3.7libmultiprocessingspawn.py”, in _check_not_importing_main is not going to be frozen to produce an executable.
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:
Solution:
将程序用if __name__ == '__main__':包裹起来,或者更全面:
if __name__ == '__main__':
freeze_support()
(1)产生原因是Windows没有fork,只有Unix有,是一个可以帮助child process识别parent process 的
(2)对于python 里的multiprocessing, if __name__ == '__main__':不可少。
Bear in mind that if code run in a child process tries to access a global variable, then the value it sees (if any) may not be the same as the value in the parent process at the time that Process.start was called.
However, global variables which are just module level constants cause no problems.Safe importing of main module. Make sure that the main module can be safely imported by a new Python interpreter without causing unintended side effects (such a starting a new process).
For example, using the spawn or forkserver start method running the following module would fail with a RuntimeError:
from multiprocessing import Process
def foo():
print('hello')
p = Process(target=foo)
p.start()
Instead one should protect the “entry point” of the program by using if __name__ == '__main__':as follows:
from multiprocessing import Process, freeze_support, set_start_method
def foo():
print('hello')
if __name__ == '__main__':
freeze_support()
set_start_method('spawn')
p = Process(target=foo)
p.start()
The freeze_support() line can be omitted if the program will be run normally instead of frozen.This allows the newly spawned Python interpreter to safely import the module and then run the module’s foo() function.
Similar restrictions apply if a pool or manager is created in the main module.



