zoukankan      html  css  js  c++  java
  • 5多进程和多线程执行的不确定性

    """多进程执行的不确定性"""


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

    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)

    def main():
    for i in range(3):
    Process(target=do_sth).start()

    do_sth()


    if __name__ == '__main__':
    main()


    ############################################################################################


    """多线程执行的不确定性"""

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

    from threading import Thread, current_thread
    import time

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


    for i in range(3):
    Thread(target=do_sth).start()

    do_sth()
  • 相关阅读:
    easyui-tabs扩展根据自定义属性打开页签
    nhibernate 3.x新特性
    c# dynamic的属性是个变量
    草稿
    好番记录
    今日内容
    PHP Filter
    PHP Filesystem
    PHP Directory 函数
    PHP Date/Time 函数
  • 原文地址:https://www.cnblogs.com/sruzzg/p/12991898.html
Copyright © 2011-2022 走看看