Update app2.py
Browse files
app2.py
CHANGED
@@ -342,9 +342,37 @@ def start():
|
|
342 |
# 在这里处理异常的代码
|
343 |
print(f"An error occurred: {e}")
|
344 |
|
|
|
|
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
net_thread = threading.Thread(target=zrok)
|
347 |
|
348 |
net_thread.start()
|
|
|
349 |
|
350 |
-
monitor_gpu()
|
|
|
|
342 |
# 在这里处理异常的代码
|
343 |
print(f"An error occurred: {e}")
|
344 |
|
345 |
+
# 实例保活
|
346 |
+
import time
|
347 |
|
348 |
+
def session_saver():
|
349 |
+
try:
|
350 |
+
import cupy as cp
|
351 |
+
except ImportError:
|
352 |
+
print("cupy模块未安装,正在安装...")
|
353 |
+
try:
|
354 |
+
import pip
|
355 |
+
pip.main(['install', 'cupy'])
|
356 |
+
import cupy as cp
|
357 |
+
except ImportError:
|
358 |
+
print("无法安装模块,请确保已正确安装pip。")
|
359 |
+
return
|
360 |
+
|
361 |
+
while True:
|
362 |
+
for _ in range(5):
|
363 |
+
matrix_a = cp.random.rand(10000, 10000)
|
364 |
+
matrix_b = cp.random.rand(10000, 10000)
|
365 |
+
result = cp.dot(matrix_a, matrix_b)
|
366 |
+
print("实例保活:", result)
|
367 |
+
del matrix_a, matrix_b, result
|
368 |
+
cp.cuda.Stream.null.synchronize()
|
369 |
+
time.sleep(600)
|
370 |
+
|
371 |
+
keepliving_thread = threading.Thread(target=session_saver)
|
372 |
net_thread = threading.Thread(target=zrok)
|
373 |
|
374 |
net_thread.start()
|
375 |
+
keepliving_thread.start()
|
376 |
|
377 |
+
monitor_gpu()
|
378 |
+
keepliving_thread.join()
|