Python practice N2 Process

Source: Internet
Author: User

#-*-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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.