分类 Python 中的文章

Python-上下文管理器

原理 执行 contextor 以获取上下文管理器 加载上下文管理器的 exit() 方法以备稍后调用 调用上下文管理器的 enter() 方法 如果有 as var 从句,则将 enter() 方法的返回值赋给 var 执行……

阅读全文

Python-时间转换

掌握几种对象及其关系 了解每类对象的基本操作方法 通过转化关系转化 time对象 datetime >>> import datetime >>> now = datetime.datetime.now() >>> now datetime.datetime(2015, 1, 12, 23, 9, 12, 946118) >>> type(now) <type 'datetime.datetime'> timestamp >>> import time >>> time.time() 1421075455.568243 time……

阅读全文

Python-多线程注意事项

锁申请位置错误导致内存泄露-多线程内存泄露注意事项 # encoding: UTF-8 import threading import time def show_fun(sem, n): # 不能放在这里 # sem_lock.acquire() print("{0}start -- {1}".format(time.ctime(), n)) print "working" time.sleep(2) print("{0}end -- {1}".format(time.ctime(), n)) sem.release() if __name__ == '__main__': max_connections = 5 semaphore = threading.BoundedSemaphore(max_connections)……

阅读全文

Supervisord-使用文档

环境依赖 # python2.7版本 # supervisord支持include功能 安装 # 建议最新版本 pip install supervisor==4.1.0 配置 # /root/.virtualenvs/test/bin/echo_supervisord_conf # 如果是virtual……

阅读全文