Gitlib Gitlib
首页
  • 分类
  • 标签
  • 归档
  • Golang开发实践万字总结
  • MySQL核心知识汇总
  • Redis实践总结
  • MQ实践万字总结
  • Docker数据持久化总结
  • Docker网络模式深度解读
  • 常用游戏反外挂技术总结
  • 读书笔记
  • 心情杂货
  • 行业杂谈
  • 友情链接
关于我
GitHub (opens new window)

Ravior

以梦为马,莫负韶华
首页
  • 分类
  • 标签
  • 归档
  • Golang开发实践万字总结
  • MySQL核心知识汇总
  • Redis实践总结
  • MQ实践万字总结
  • Docker数据持久化总结
  • Docker网络模式深度解读
  • 常用游戏反外挂技术总结
  • 读书笔记
  • 心情杂货
  • 行业杂谈
  • 友情链接
关于我
GitHub (opens new window)
  • PHP

  • Golang

  • Python

    • Python使用lambda表达式
    • Python之线程池
    • Python之装饰器
    • Python之chardet模块使用
    • Python之copy模块使用
    • Python之functools模块使用
    • Python之hashlib模块使用
    • Python之json模块使用
    • Python之pickle模块使用
    • Python之pid模块使用
      • 安装
      • 主要方法
      • 代码测试
    • Python之pypinyin模块使用
    • Python之pyqrcode模块使用
    • Python之threading模块使用
    • Python之base64模块使用
    • Python项目Docker打包
  • Javascript

  • 其他语言

  • 编程语言
  • Python
Ravior
2014-07-27
目录

Python之pid模块使用

pid文件主要用来保存当前程序的PID,并将pid写入到文件中, 在程序执行期间,将锁定这个文件,常用来防止程序重复启动。

# 安装

pip install pip
1

# 主要方法

  • PidFile(): 创建pid文件,可设置pid文件存储目录,文件名

# 代码测试

# encoding=utf-8
# pip install pid

import logging
from pid import PidFile
import time

logging.basicConfig(level = logging.DEBUG, format='%(levelname)s - %(message)s')

logger = logging.getLogger(__name__)

# 执行完成pid文件将会自动删除
with PidFile(piddir='./tmp/',pidname='pidtest'):
	time.sleep(30)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

在程序没有执行完成,再次运行这个程序时,会出现报错:

Traceback (most recent call last):
  File "pid.test.py", line 13, in <module>
    with PidFile(piddir='./tmp/',pidname='pidtest'):
  File "/usr/local/lib/python2.7/site-packages/pid/__init__.py", line 217, in __enter__
    self.create()
  File "/usr/local/lib/python2.7/site-packages/pid/__init__.py", line 178, in create
    raise PidFileAlreadyLockedError(exc)
pid.PidFileAlreadyLockedError: [Errno 35] Resource temporarily unavailable
1
2
3
4
5
6
7
8
#Python
上次更新: 2022/12/01, 11:09:34
Python之pickle模块使用
Python之pypinyin模块使用

← Python之pickle模块使用 Python之pypinyin模块使用→

最近更新
01
常用游戏反外挂技术总结
11-27
02
Golang开发实践万字总结
11-11
03
Redis万字总结
10-30
更多文章>
Theme by Vdoing | Copyright © 2011-2022 Ravior | 粤ICP备17060229号-3 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式