易截截图软件、单文件、免安装、纯绿色、仅160KB

Python监视进程


由subprocess创建一个进程,然后进行监视
每一秒钟查看一次,如果正在运行,打印pid和running,如果已停止,,继续执行任务并打印Termined
shell和stdout均设置为False
也许这对做病毒的守护进程很好
#!/usr/bin/env python
import subprocess , sys , time
p=subprocess.Popen(['ping','127.0.0.1','-n','10'], shell=False,stdout=False)
while 1:
    time.sleep(1)
    ret=subprocess.Popen.poll(p)
    if ret is None:
        print p.pid,"running"
    else:
        print "Termined!"
        p=subprocess.Popen(['ping','127.0.0.1','-n','10'], shell=False,stdout=False)


相关文档:

python技术资料

python中国论坛     http://www.okpython.com/bbs/index.php
开源社区   http://sourceforge.net/
python官网  http://www.python.org/
pythonIDE BOAhttp://boa-constructor.sourceforge.net/
pythonIDE 大全http://www.oschina.net/project/tag/120
python组件http://py.dw ......

Python 线程操作

在python中如何创建一个线程对象
如果你要创建一个线程对象,很简单,只要你的类继承threading.Thread,然后在__init__里首先调用threading.Thread的__init__方法即可
import threading
class mythread(threading.Thread):
    def __init__(self, threadname):
      & ......

python中文件和目录操作

1.获得当前路径
在Python中可以使用os.getcwd()函数获得当前的路径。其原型如下所示。
os.getcwd()
该函数不需要传递参数,它返回当前的目录。需要说明的是,当前目录并不是指脚本所在的目录,而是所运行脚本的目录。例如,在PythonWin中输入如下脚本。
>>> import os
>>> print 'current director ......

python 函数

Python中函数参数的传递是通过“赋值”来传递的。但这条规则只回答了函数参数传递的“战略问题”,并没有回答“战术问题”,也就说没有回答怎么赋值的问题。函数参数的使用可以分为两个方面,一是函数参数如何定义,二是函数在调用时的参数如何解析的。而后者又是由前者决定的。函数参数的定 ......

PEP 0263 Defining Python Source Code Encodings

 
PEP 0263
Defining Python Source Code Encodings
Python will default to ASCII as standard encoding if no other
encoding hints are given.
To define a source code encoding, a magic comment must
be placed into the source files either as first or second
line in the file, suc ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号