5

Python多进程、多线程的不确定性及守护与阻塞进程和线程join()方法使用 | CHEGVA

 1 year ago
source link: https://chegva.com/5572.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python高级(5)—多进程、多线程的不确定性及守护与阻塞进程和线程join()方法使用

◎知识点

  1. 多进程执行的不确定性

  2. 多线程执行的不确定性

  3. 阻塞父进程的子进程之方法join()

  4. 阻塞父线程的子线程之方法join()

  5. 守护父进程的子进程

  6. 守护父线程的子线程

◎脚本练习

多进程执行的不确定性

"""
    默认情况下,多个进程的执行顺序和时间都是不确定的,完全取决于操作系统的调度
"""

"""
from multiprocessing import Process, current_process
import time

def do_sth():
    for i in range(5):
        print('%s: %d' % (current_process().name, i))
        time.sleep(2)

if __name__ == '__main__':
    for i in range(3):
        Process(target=do_sth).start()

    do_sth()
"""
Python

Python高级(5)—多进程、多线程的不确定性及守护与阻塞进程和线程join()方法使用
安志合个人博客,版权所有 丨 如未注明,均为原创 丨 转载请注明转自:https://chegva.com/5572.html | ☆★★每天进步一点点,加油!★★☆ | 

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK