zoukankan      html  css  js  c++  java
  • Python线程和进程

    多线程

     1 import threading
     2 from time import ctime,sleep
     3 
     4 def m(func):
     5     for i in range(6):
     6         print (func ,'%s' % ctime())
     7         sleep(1)
     8 
     9 def v(func):
    10     for i in range(6):
    11         print (func,'%s' % ctime())
    12         sleep(2)
    13 
    14 threads = []
    15 
    16 t1 = threading.Thread(target=m,args=('a',))
    17 threads.append(t1)
    18 t2 = threading.Thread(target=v,args=('b',))
    19 threads.append(t2)
    20 
    21 for t in threads:
    22     t.start()
    23 for t in threads:
    24     t.join()

     1 #coding:utf8
     2 import multiprocessing
     3 import os
     4 
     5 def a(b):
     6     print 'x'
     7     print b,os.getpid()
     8 
     9 def b():
    10     print 'asd'
    11 
    12 if __name__ == '__main__':        #win下只能控制台打开
    13     p1 = multiprocessing.Process(target=a,args=('u',))
    14     p2 = multiprocessing.Process(target=b,args=())
    15     p1.start()
    16     p2.start()
    17     p1.join()
    18     p2.join()
  • 相关阅读:
    configparser模块
    xml文件解析
    shutil模块 + shelve模块 二合一版
    hashlib模块
    subprocess模块和sys模块
    re模块
    os模块
    random模块
    time模块、datetime模块讲解
    洛谷P3414 SAC#1
  • 原文地址:https://www.cnblogs.com/qqzj/p/6641670.html
Copyright © 2011-2022 走看看