Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf4d1d90

Browse files
committed
Logging instead of printing
1 parentdc8683e commitf4d1d90

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

‎backend/main/workers/master.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importatexit
2+
importlogging
23
importmultiprocessing
34
importqueue
45
fromcollectionsimportdefaultdict,deque
@@ -18,6 +19,8 @@
1819

1920
TESTING=False
2021

22+
log=logging.getLogger(__name__)
23+
2124

2225
classUserProcess:
2326
def__init__(self):
@@ -87,7 +90,7 @@ def _await_result(self):
8790
assert (resultisNone)==self.fresh_process
8891
exceptqueue.Empty:
8992
alive=self.process.is_alive()
90-
print(f"Process{alive=}")
93+
log.info(f"Process{alive=}")
9194
ifalive:
9295
self.process.terminate()
9396
self.start_process()
@@ -120,15 +123,15 @@ def monitor_processes():
120123
sleep(MONITOR.SLEEP_TIME)
121124
percent=psutil.virtual_memory().percent
122125
history.append(percent)
123-
print(f"Recent memory usage:{history}")
124-
print(f"Number of user processes:{len(user_processes)}")
126+
log.info(f"Recent memory usage:{history}")
127+
log.info(f"Number of user processes:{len(user_processes)}")
125128
if (
126129
len(history)==history.maxlen
127130
andmin(history)>MONITOR.THRESHOLD
128131
andlen(user_processes)>MONITOR.MIN_PROCESSES
129132
):
130133
oldest=min(user_processes.values(),key=lambdap:p.last_used)
131-
print(f"Terminating process last used{int(time()-oldest.last_used)} seconds ago")
134+
log.info(f"Terminating process last used{int(time()-oldest.last_used)} seconds ago")
132135
deluser_processes[oldest.user_id]
133136
oldest.close()
134137
history.clear()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp