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()
  • 相关阅读:
    枚举
    泛型
    装箱和拆箱
    使用TryParse()来执行数值转换
    参数数组
    checked和unchecked转换
    字符串不可变
    TCC : Tiny C Compiler (2018-2-6)
    win10 下 protobuf 与 qt
    QWebView 与Js 交互
  • 原文地址:https://www.cnblogs.com/qqzj/p/6641670.html
Copyright © 2011-2022 走看看