Python timer using sample sharing

Source: Internet
Author: User
Copy CodeThe code is as follows:


Class Sltimer (multiprocessing. Process):
#from datetime Import DateTime
#import time

def __init__ (self, Target=none, args= (), Kwargs={},date=none,time=none):
'''\
@param date 1900-01-01
@param time 00:00:00
'''
Super (Sltimer,self) __init__ (Target=target,args=args,kwargs=kwargs)
_date = ' '
If date is None:
_date = DateTime.Now (). __str__ () [: 10]
else:
_date = Date

_time = ' '
If time is None:
_time = DateTime.Now (). __str__ () [11:19]
Else
_time = time

Self.__runtime = '%s%s '% (_date,_time)

def run (self):
Timelen = Len (' 1900-00-00 00:00:00 ')

While True:
now = DateTime.Now (). __str__ () [: Timelen]
If Now>=self.__runtime:
Break
print ' sleeping ...%s '% now
Time.sleep (1.0)

Super (Sltimer,self). Run ()

Test

Copy the Code code as follows:


Def show1 ():
From datetime import datetime
print ' hello,current time:%s '% DateTime.Now (). __str__ ()

Def t23 ():
From Stock.task import Sltimer

Timer = Sltimer (Show1, time= ' 16:31:50 ')
Timer.start ()

  • 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.