代码拉取完成,页面将自动刷新
# -*- coding: utf-8 -*-
import socket
import time
import traceback
import os
class LogClient(object):
"""docstring for LogClient"""
def __init__(self, port=None):
super(LogClient, self).__init__()
if port is None:
port = 10909
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.addr = ('127.0.0.1', port)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.sock.close()
def write(self, msg):
if not isinstance(msg, bytes):
msg = msg.encode('utf-8', 'ignore')
send = self.sock.sendto(msg, self.addr)
# print(send)
def print_log(msg, port=None):
try:
with LogClient(port) as lc:
# print(msg, file=lc, end='')
lc.write(msg)
except Exception as e:
traceback.print_exc()
print(msg)
if __name__ == '__main__':
for i in range(10):
print(i)
msg = 'log client msg\n msg [{0}]'.format(i)
print_log(msg)
time.sleep(1)
'''
class Test(object):
def __init__(self):
super(Test, self).__init__()
print('print __init__')
def __enter__(self):
print('print __enter__')
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print('print __exit__')
'''
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。