- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我们有一个遗留的 C
编写的程序,可以将日志输出到文本文件,并且该程序能够每天轮换日志。
例如
app.log
app.log.2012-10-24
app.log.2012-10-23
..
现在我想写一个 python 守护进程来追踪日志并注入(inject)数据库,我的问题
Twisted
还是 Pyinotify
?谢谢。
最佳答案
我遇到过类似的问题。我的做法是这样的:
import io
import time
def checklog(fs,logfile):
trytimes = 10
line = ''
while line == '':
time.sleep(1)
line = fs.readline().replace('\n','')
trytimes = trytimes - 1
while trytimes == 0 and line == '':
try:
fs = io.open(logfile,'rb')
fs.seek(0,2)
trytimes = 10
break
except:
time.sleep(10)
return line,fs
logfile="app.log"
fs = io.open(logfile,'rb')
fs.seek(0,2)# seek to tail of the logfile
while True:
line = fs.readline().replace('\n','')
while line == '':
line,fs = checklog(fs,logfile)
#do something for line;
希望这对您有所帮助。
关于python - 使用 Python 记录拖尾守护进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13132461/
一 点睛 线程可以设置为守护线程,ThreadGroup 也可以设置为守护 ThreadGroup,但是若将一个 ThreadGroup 设置为 deamon,也并不会影响线程的 daemon 属性,
我有一个 python 脚本需要在启动时作为守护进程运行。进程从 tty(和 pdb)分离,但代码不运行。 我已经将它缩小到一个最小的例子 import daemon from time import
reactjs isMounted API 的文档提到: You can use this method to guard asynchronous calls to setState() or fo
我正在开发一个需要嵌入 HTTP 服务器的守护进程。我正在尝试使用 BaseHTTPServer 来完成它,当我在前台运行它时,它工作正常,但是当我尝试将守护进程 fork 到后台时,它停止工作。我的
我正在尝试使用 Apache Commons Daemon 使用 Daemon 接口(interface)来守护我的应用程序。 Java 应用程序本身不执行任何操作,只是写入 stout。 我编译了j
我正在使用 Bootle Python Web Framework 在 Ubuntu 上开发网络应用程序。是否有任何有效的方法来守护启动默认 bottlepy 网络服务器的脚本? 谢谢。 UPD:现在
我一直使用 bluepill成功地守护简单的 Ruby 脚本。然而这一次,我有一个脚本,它也在加载 Rails 环境,因此我可以访问 Rails 应用程序及其各自模型的数据库连接。我使用的 bluep
我试图守护一些代码,但我遇到了一些麻烦。 如果我用 tklogger() 调用代码,它运行得很好。但是,如果我在守护程序上下文中调用它,我会得到以下跟踪信息: Traceback (most rece
我打算使用 systemd 将 celery 4.3.0 作为守护进程运行,但它给了我这个错误: 它会启动 worker 但会很快停止它们。但是,我可以通过键入以下命令手动运行工作人员: celery
我是一名优秀的程序员,十分优秀!