Two ways to open a process in Python

Source: Internet
Author: User

1. How to open a process

 fromMultiprocessingImportProcessImport TimedefWork (name):#Define a function    Print('task <%s> is runing'%name) Time.sleep (1)    Print('task <%s> is AAAAA'%name)if __name__=='__main__': P1=process (target=work,args= ('Yxwang',))#produces a process object, followed by the name of the function to be executed. Here, args and a tupleP2=process (target=work,kwargs={'name':'User01'})#You can also use the Kwargs and dictionary method. P1.start ()#execution. is equal to running a child process under the current program. P2.start ()Print('QQQQQQQQQQ')

Execution Result:

2. The second way to open a process

 fromMultiprocessingImportProcessImport TimeclassMyprocess (Process):#inherit the Process class    def __init__(Self,name): Super ().__init__()#invokes a method in the parent class. Self.name=namedefRun (self):#there must be a way to run.        Print('task <%s> is runing'%self.name) Time.sleep (1)        Print('task <%s> is AAAAA'%self.name)if __name__=='__main__': P=myprocess ('Egon')#get an objectP.start ()#Run    Print('TTTTTT')

Two ways to open a process in Python

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.