当前位置:网站首页>Process (P) runs, and idle is different from pycharm

Process (P) runs, and idle is different from pycharm

2022-07-05 07:29:00 work-harder

background :

win8.1, python idle 3.9.7, pycharm 2021.3.1

The phenomenon :

process (p) Code to run after creation , stay idle China and pycharm Different .

terms of settlement :

pycharm Sub processes can be called in : p.start() and p.run() Fine

#idle in , only p.run() Can call the subprocess ,p.start() no way .

[ to update ] idle in , p.run() Will execute sub processes print sentence , but p.start() Not execute print sentence . If there is time.sleep() sentence ,p.start() Will perform time.sleep() sentence .

[ to update ] use vs code ( My is 1.64.2) Can be fully demonstrated p.join() and p.join(timeout) The role of

Example

from multiprocessing import Process
from time import sleep # to update 


def run_test():
    print("...run_test  Start ...") # to update 
    sleep(10)                    # to update 
    print("...run_test  end ...") # to update 



if __name__ == "__main__":
    print(" Main process in progress ")
    #p = Process(target=run_test()) #  No call required p.run()
    p = Process(target=run_test)
    #p.start() # Only in pycharm Can be called run_test
    p.run() # stay pycharm (2021.3.1)  and  idle(python3.9.7 Bring their own ) You can call run_test

原网站

版权声明
本文为[work-harder]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140555475425.html