#-*-coding:cp936-*-
Import time,threading,logging
Logging.basicconfig (level=logging. DEBUG,
Format= ' (% (threadname) -10s)% (message) s ',)
Def de ():
Logging.debug (' staring ')
Time.sleep (2)
Logging.debug (' exitng ')
D=threading. Thread (name= ' de ', target=de) #Thread对对象进行实例化
D.setdaemon (True) #标识一个进程需要这个
def non ():
Logging.debug (' staring ')
Logging.debug (' exitng ')
T=threading. Thread (name= ' non ', Target=non)
D.start () #开始一个进程需要这个
T.start ()
D.join (1) #等待结束一个进程需要这个
print ' d,isalive () ', d.isalive () #线程是否在运行
T.join () #join (1) indicates output after 1 seconds, normally time is floating point time
#threading. Enumerate () Returns the list of activities
#threading. The timer (number of seconds, function) the thread of a function that executes at a specified interval of time.
#t2. Cancel () logout, cancel
#threading. Event () Management internal flag
Both #set () and clear () calls can use these 2 controls for this flag
#其他线程暂停可以使用wait () parameters can be added in parentheses
Def woker ():
Print Threading.currentthread (). GetName (), ' starting '
Time.sleep (2)
Print Threading.currentthread (). GetName (), ' extarting '
Def worke1 ():
Print Threading.currentthread (). GetName (), ' starting '
Time.sleep (3)
Print Threading.currentthread (). GetName (), ' extarting '
T=threading. Thread (name= ' worke1 ', target=worke1)
T2=threading. Thread (name= ' Woker ', Target=woker)
T3=threading. Thread (Target=woker)
T2.start ()
T3.start ()
T.start ()
Python practice N2 Process