【用Python做个QQ邮箱定时发送天气预报给女神,教你呵护心爱的她!】教程文章相关的互联网学习教程文章

详解使用pythoncrontab设置linux定时任务

熟悉linux的朋友应该知道在linux中可以使用crontab设置定时任务。可以通过命令crontab -e编写任务。当然也可以直接写配置文件设置任务。但是有时候希望通过脚本自动设置,比如我们应用程序部署时等。有需求当然就得想办法解决,不然在程序猿界混(一群自得其乐的猿)。下面进入正题,开始想通过以写文件的形式设置,通过在配置文件中直接追加一行即可。但是读写文件难免有点繁琐,再比如:设置任务时要检查任务是否已经存在;根据输...

深入浅析python定时杀进程

这篇文章主要介绍了深入浅析python定时杀进程的相关资料,需要的朋友可以参考下之前写了个python脚本用selenium+phantomjs爬新帖子,在循环拉取页面的过程中,phantomjs总是block住,使用WebDriverWait设置最长等待时间无效。用firefox替换phantomjs无改善因为这个脚本不会长期使用,因此采取临时办法,新开一个子线程固定周期杀死phantomjs进程,这样selenium就会在block最多不超过此周期后返回。当然在爬虫脚本中做一些微调防止部...

Python实现定时弹窗提醒

经常用电脑,一坐就是几个小时,总是忘记时间,所以觉得是不是找个定时提醒软件。网上找了还真有还很多,找了一个卫士什么的,装了。到时间以后自动锁屏倒计时。功能不错但是感觉功能太多。不知道大家现在用软件的时候有没有这种感觉,本来就是想要一种很简单的功能,但最惨的是装了一大堆软件,功能一大票但是没有自己用的。 其实自己想的就是到时间以后弹窗提示休息就可以了。后来想想还是自己做一个吧。当然首选Python语言...

通过reidis管理定时任务

主要应用场景为:有变动需求的一次性定时任务。 通过redis过期事件的监听,执行相应命令。(注意:因为监听只能得到key, 所以需要另外存储具体执行内容体) 另外记得修改redis配置:notify-keyspace-events Ex import redis rdc = redis.StrictRedis() pubsub = rdc.pubsub() pubsub.psubscribe("__keyevent@0__:expired") while pubsub.subscribed: msg = pubsub.get_message() if msg: print msg

python定时检查启动某个exe程序适合检测exe是否挂了

详见代码如下: 代码如下: import threading import time import os import subprocess def get_process_count(imagename): p = os.popen(tasklist /FI "IMAGENAME eq %s" % imagename) return p.read().count(imagename) def timer_start(): t = threading.Timer(120,watch_func,("is running...")) t.start() def watch_func(msg): print "Im watch_func,",msg if get_process_count(main.exe) == 0 : print subprocess.Popen([...

python定时采集摄像头图像上传ftp服务器功能实现

首先是截图,从摄像头截取一幅图像:代码如下:while 1: #测试摄像头的存在 try: cam = Device() except: print "no webcam found!" continue break 然后是把图像上传到ftp服务器:代码如下:remote = ftplib.FTP(127.0.0.1) #登陆服务器remote.login()file = open(%s.jpg%cur_time,rb) #用时间来命名图片remote.storbinary(STOR %s.jpg%cur_time,file) #上传图片file.close() 当然了,最后把图片删除...

python定时器使用示例分享

代码如下:class SLTimer(multiprocessing.Process): #from datetime import datetime #import timedef __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...

python单线程实现多个定时器示例

单线程实现多个定时器 NewTimer.py 代码如下:#!/usr/bin/env python from heapq import *from threading import Timerimport threadingimport uuidimport timeimport datetimeimport sysimport math global TimerStampglobal TimerTimesclass CancelFail(Exception): pass class Slot(object): def __init__(self, period=0, interval=1, function=None, args=[], kwargs={}): self.period = period self.pc =...

python实现定时同步本机与北京时间的方法

本文实例讲述了python实现定时同步本机与北京时间的方法。分享给大家供大家参考。具体如下: 这段python代码首先从www.beijing-time.org上获取标准的北京时间,然后同步获取的北京时间到本地# -*- coding: utf-8 -*- import time,httplib import threading def getBeijinTime():try:conn = httplib.HTTPConnection("www.beijing-time.org")conn.request("GET", "/time.asp")response = conn.getresponse()print response.status, r...

用Python编写简单的定时器的方法

下面介绍以threading模块来实现定时器的方法。 首先介绍一个最简单实现:import threadingdef say_sth(str):print strt = threading.Timer(2.0, say_sth,[str])t.start()if __name__ == __main__:timer = threading.Timer(2.0,say_sth,[i am here too.])timer.start()不清楚在某些特殊应用场景下有什么缺陷否。 下面是所要介绍的定时器类的实现:class Timer(threading.Thread): """ very simple but useless timer. """ def __ini...

python使用线程封装的一个简单定时器类实例

本文实例讲述了python使用线程封装的一个简单定时器类。分享给大家供大家参考。具体实现方法如下:from threading import Timer class MyTimer:def __init__(self):self._timer= Noneself._tm = Noneself._fn = Nonedef _do_func(self):if self._fn:self._fn()self._do_start()def _do_start(self):self._timer = Timer(self._tm, self._do_func)self._timer.start()def start(self, tm, fn):self._fn = fnself._tm = tmself._do_s...

python定时检查某个进程是否已经关闭的方法

本文实例讲述了python定时检查某个进程是否已经关闭的方法。分享给大家供大家参考。具体如下:import threading import time import os import subprocess def get_process_count(imagename):p = os.popen(tasklist /FI "IMAGENAME eq %s" % imagename)return p.read().count(imagename) def timer_start():t = threading.Timer(120,watch_func,("is running..."))t.start() def watch_func(msg):print "Im watch_func,",msgif get...

python定时执行指定函数的方法

本文实例讲述了python定时执行指定函数的方法。分享给大家供大家参考。具体实现方法如下:# time a function using time.time() and the a @ function decorator # tested with Python24 vegaseat 21aug2005 import time def print_timing(func):def wrapper(*arg):t1 = time.time()res = func(*arg)t2 = time.time()print %s took %0.3f ms % (func.func_name, (t2-t1)*1000.0)return resreturn wrapper # declare the @ decora...

wxPython定时器wx.Timer简单应用实例【图】

本文实例讲述了wxPython定时器wx.Timer简单应用。分享给大家供大家参考。具体如下:# -*- coding: utf-8 -*- ######################################################## ## 这是wxPython定时器wx.Timer的简单应用 ## testwxTimer1.pyw ######################################################## import wx import time ######################################################## class MyFrame1 ( wx.Frame ): def __i...

python定时器(Timer)用法简单实例

本文实例讲述了python定时器(Timer)用法。分享给大家供大家参考。具体如下:# encoding: UTF-8 import threading #Timer(定时器)是Thread的派生类, #用于在指定时间后调用一个方法。 def func():print hello timer! timer = threading.Timer(5, func) timer.start()该程序可实现延迟5秒后调用func方法的功能。 希望本文所述对大家的Python程序设计有所帮助。