forked from oe-mirrors/e2m3u2bouquet-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.py
38 lines (32 loc) · 756 Bytes
/
log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# logging
#
# One can simply use
# import log
# print("Some text", file=log)
# because the log unit looks enough like a file!
import sys
import threading
from six.moves import cStringIO as StringIO
logfile = StringIO()
# Need to make our operations thread-safe.
mutex = threading.Lock()
def write(data):
mutex.acquire()
try:
if logfile.tell() > 2000:
# Do a sort of 2k round robin
logfile.seek(0)
logfile.write(data)
finally:
mutex.release()
sys.stdout.write(data)
def getvalue():
mutex.acquire()
try:
pos = logfile.tell()
head = logfile.read()
logfile.seek(0)
tail = logfile.read(pos)
finally:
mutex.release()
return head + tail