+ 1

pls i need a comprehensive explanation of what this statement does "if __name__=='__main__':". i still don't fully understand it

14th Sep 2017, 8:37 AM
Owolawi Kehinde
Owolawi Kehinde - avatar
2 Antworten
+ 1
python-shell-send-buffer is an interactive compiled Lisp function in `python.el'. (python-shell-send-buffer &optional ARG) Send the entire buffer to inferior Python process. With prefix ARG allow execution of code inside blocks delimited by "if __name__=='__main__':" def do_stuff_with_pcl(pcl): print(pcl) if __name__ == "__main__": # multiprocessing code, etc pcl = ... do_stuff_with_pcl(pcl) When multiprocessing creates a new process for its Pool, it needs to initialize that process with a copy of the current module's state. Because Windows doesn't have fork (which copies the parent process's memory into a child process automatically), Python needs to set everything up from scratch. In each child process, it loads the module from its file, and if you the module's top-level code tries to create a new Pool, you'd have a recursive situation where each of the child process would start spawning a whole new set of child processes of its own.
14th Sep 2017, 8:48 AM
MsJ
MsJ - avatar
0
it better to show an example. (see comments to the code) https://code.sololearn.com/cQlE5br3BBsp/?ref=app
14th Sep 2017, 12:24 PM
yuri