码迷,mamicode.com
首页 > 编程语言 > 详细

python响应websocket请求输出动态日志

时间:2020-12-30 10:45:44      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:打开文件   文件   code   readline   read   line   class   python   log   

处理线程中打开文件,每次读取一行并记录当前读取位置,没有下一行让出一秒
logfile = ‘./logs/%s_%s.log‘ % (appName, time.strftime(‘%Y_%m_%d‘)) file = open(logfile, ‘r‘, encoding=‘utf-8‘) while True: where = file.tell() line = file.readline() if not line: time.sleep(1) file.seek(where) else: send_data(conn, line.strip().encode(‘utf-8‘))

 

python响应websocket请求输出动态日志

标签:打开文件   文件   code   readline   read   line   class   python   log   

原文地址:https://www.cnblogs.com/6min/p/14185660.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!