Python performs the same task non-blocking mode every 1s

Source: Internet
Author: User


First we use crontab every 1 minutes to perform, look at the effect, and then in doing this,

Configure Crontab

[Email protected] ~]# crontab-l

*/1 * * * * Ping www.baidu.com >/dev/nul

Note that I deliberately wrote such an order to always ping, the purpose is when entering the next minute, the system will automatically open another process to execute, in order to see the effect

By looking at the Crontab log, we can see that two

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/91/wKiom1RrAXShg3_7AAFXYgiVS-Q926.jpg "title=" 1.png " alt= "Wkiom1rraxshg3_7aafxygivs-q926.jpg"/>

Because this command will always ping, so when you look at the PS-EF, there will be two

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/8F/wKioL1RrAumjaNHRAAG8Mv0PXoE762.jpg "title=" 2.png " alt= "Wkiol1rraumjanhraag8mv0pxoe762.jpg"/>

Next we test the script we wrote every 1s, to see whether the same effect as crontab

The script content is as follows

Import threading

Import Time,os


def run ():

Os.system (' ping www.baidu.com >/dev/nul ')


I=0

While i<3:

I+=1

Print "Start", Time.strftime ("%y-%m-%d_%h-%m-%s")

t = Threading. Thread (target=run,args= ())

T.start ()

Time.sleep (1)

Print "End", Time.strftime ("%y-%m-%d_%h-%m-%s")

As a result of testing I have limited to 3 times, easy to see the effect, if you want to continue to change to while true

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/53/8F/wKioL1RrBPuAmVWFAAEpe1tOf4c410.jpg "title=" 3.png " alt= "Wkiol1rrbpuamvwfaaepe1tof4c410.jpg"/>

From can be seen every 1s execution, altogether performed 3 times,

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/53/8F/wKioL1RrBR_wyCHkAAKYV1JY1f4825.jpg "title=" 4.png " alt= "Wkiol1rrbr_wychkaakyv1jy1f4825.jpg"/> can be seen to open 3 processes to ping, with the effect of crontab is the same, do not wait until the last command execution finished to see is executed, but as long as the specified point, We're going to start a new process.

This article is from the "Server" blog, so be sure to keep this source http://zhangfang2012.blog.51cto.com/6380212/1579172

Python performs the same task non-blocking mode every 1s

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.