we probably don't need this lock
This commit is contained in:
@@ -19,7 +19,7 @@ class LogFileModel:
|
|||||||
def __init__(self, file: str, settings: Settings):
|
def __init__(self, file: str, settings: Settings):
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self._file = os.path.realpath(file)
|
self._file = os.path.realpath(file)
|
||||||
self._lock = threading.RLock()
|
# self._lock = threading.RLock()
|
||||||
|
|
||||||
def highlighters(self):
|
def highlighters(self):
|
||||||
return Highlighting.read_config(self.settings)
|
return Highlighting.read_config(self.settings)
|
||||||
@@ -50,7 +50,8 @@ class LogFileModel:
|
|||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
def read_range(self, start_byte: int, end_byte: int):
|
def read_range(self, start_byte: int, end_byte: int):
|
||||||
with self._lock:
|
# with self._lock:
|
||||||
|
if True:
|
||||||
with open(self._file, 'rb') as f:
|
with open(self._file, 'rb') as f:
|
||||||
f.seek(start_byte)
|
f.seek(start_byte)
|
||||||
bytes = f.read(end_byte - start_byte)
|
bytes = f.read(end_byte - start_byte)
|
||||||
@@ -58,7 +59,8 @@ class LogFileModel:
|
|||||||
|
|
||||||
def write_range(self, start_byte: int, end_byte: int, file: str):
|
def write_range(self, start_byte: int, end_byte: int, file: str):
|
||||||
# print("write range: %d - %d -> %s" % (start_byte, end_byte, file))
|
# print("write range: %d - %d -> %s" % (start_byte, end_byte, file))
|
||||||
with self._lock, open(self._file, 'rb') as source, open(file, "w+b") as target:
|
# with self._lock, open(self._file, 'rb') as source, open(file, "w+b") as target:
|
||||||
|
with open(self._file, 'rb') as source, open(file, "w+b") as target:
|
||||||
offset = start_byte
|
offset = start_byte
|
||||||
source.seek(offset)
|
source.seek(offset)
|
||||||
while offset < end_byte:
|
while offset < end_byte:
|
||||||
@@ -75,14 +77,17 @@ class LogFileModel:
|
|||||||
lines_to_find = lines + abs(scroll_lines)
|
lines_to_find = lines + abs(scroll_lines)
|
||||||
lines_to_return = math.ceil(lines)
|
lines_to_return = math.ceil(lines)
|
||||||
|
|
||||||
# start = time.time()
|
start = time.time()
|
||||||
with self._lock:
|
# with self._lock:
|
||||||
# print("data lock acquision %.4f" % (time.time() -start))
|
if True:
|
||||||
|
duration = time.time() - start
|
||||||
|
if duration > 10:
|
||||||
|
print("data lock acquision %.4f" % ())
|
||||||
# TODO handle lines longer than 4096 bytes
|
# TODO handle lines longer than 4096 bytes
|
||||||
# TODO abort file open after a few secons: https://docs.python.org/3/library/signal.html#example
|
# TODO abort file open after a few secons: https://docs.python.org/3/library/signal.html#example
|
||||||
with open(self._file, 'rb') as f:
|
with open(self._file, 'rb') as f:
|
||||||
offset = min(byte_offset, self.byte_count())
|
offset = min(byte_offset, self.byte_count())
|
||||||
#print("offset: %s byte_count: %d" % (offset, self.byte_count()))
|
# print("offset: %s byte_count: %d" % (offset, self.byte_count()))
|
||||||
offset = max(0, offset - self.settings.max_line_length())
|
offset = max(0, offset - self.settings.max_line_length())
|
||||||
|
|
||||||
eof_reached = True
|
eof_reached = True
|
||||||
|
|||||||
Reference in New Issue
Block a user