Skip to content

Commit 6c44281

Browse files
Quick improvements and polishing\
Also improved __performance() method accuracy Signed-off-by: Shahm Najeeb <Nirt_12023@outlook.com>
1 parent 8b4b9b7 commit 6c44281

3 files changed

Lines changed: 18 additions & 33 deletions

File tree

CODE/Logicytics.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import gc
34
import os
45
import shutil
56
import subprocess
@@ -197,14 +198,15 @@ def __performance(self):
197198

198199
execution_times = []
199200
memory_usage = []
200-
process = psutil.Process()
201+
process = psutil.Process(os.getpid())
201202

202203
for file in range(len(self.execution_list)):
204+
gc.collect()
203205
start_time = datetime.now()
204-
start_memory = process.memory_info().rss / 1024 / 1024 # MB
206+
start_memory = process.memory_full_info().uss / 1024 / 1024 # MB
205207
log.execution(Execute.script(self.execution_list[file]))
206208
end_time = datetime.now()
207-
end_memory = process.memory_info().rss / 1024 / 1024 # MB
209+
end_memory = process.memory_full_info().uss / 1024 / 1024 # MB
208210
elapsed_time = end_time - start_time
209211
memory_delta = end_memory - start_memory
210212
memory_usage.append((self.execution_list[file], str(memory_delta)))
@@ -510,8 +512,8 @@ def Logicytics():
510512
try:
511513
Logicytics()
512514
except KeyboardInterrupt:
513-
log.warning("Shutting down Logicytics utility with force causes many files to remain where they shouldn't")
514-
log.warning("Please don't force shut Logicytics again - As we don't have a cleanup function yet.")
515+
log.warning("⚠️ Force shutdown detected! Some temporary files might be left behind.")
516+
log.warning("💡 Pro tip: Next time, let the program finish naturally.")
515517
# TODO v3.4.2 -> Cleanup function
516518
exit(0)
517519
else:

CODE/logicytics/Get.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
11
from __future__ import annotations
22

3-
import functools
43
import os
5-
import time
6-
7-
8-
def time_execution(func):
9-
"""
10-
A decorator that logs the execution time of a function.
11-
12-
Usage:
13-
@time_execution
14-
def my_function():
15-
...
16-
17-
Or:
18-
time_execution(my_function, *args, **kwargs)
19-
"""
20-
21-
@functools.wraps(func)
22-
def wrapper(*args, **kwargs):
23-
start_time = time.time()
24-
result = func(*args, **kwargs)
25-
end_time = time.time()
26-
print(f"Function '{func.__name__}' executed in {end_time - start_time:.6f} seconds")
27-
return result
28-
29-
return wrapper
304

315

326
class Get:
337
@staticmethod
34-
@time_execution
358
def list_of_files(
369
directory: str,
3710
only_extensions: list[str] = None,

CODE/logicytics/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,17 @@
2525
class ObjectLoadError(Exception):
2626
"""Raised when an Object fails to load."""
2727

28-
def __init__(self, message="Failed to load object"):
28+
def __init__(self, message="Failed to load object", object_name=None):
29+
"""
30+
Initialize the exception with a custom message and object details.
31+
32+
Args:
33+
message (str): The error message
34+
object_name (str, optional): Name of the object that failed to load
35+
"""
36+
self.object_name = object_name
37+
if object_name:
38+
message = f"{message} (Object: {object_name})"
2939
super().__init__(message)
3040

3141

0 commit comments

Comments
 (0)