Update app11.py
Browse files
app11.py
CHANGED
@@ -239,6 +239,31 @@ def monitor_gpu():
|
|
239 |
print(f"Error: {e}")
|
240 |
|
241 |
time.sleep(60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
def start():
|
244 |
#try:
|
@@ -263,12 +288,15 @@ def start():
|
|
263 |
print(f"启动SD发生错误: {e}")
|
264 |
# Create threads for each function
|
265 |
wandb_thread = threading.Thread(target=monitor_gpu)
|
|
|
266 |
start_thread = threading.Thread(target=start)
|
267 |
|
268 |
# Start the threads
|
269 |
wandb_thread.start()
|
270 |
start_thread.start()
|
|
|
271 |
|
272 |
# Wait for both threads to finish
|
273 |
wandb_thread.join()
|
274 |
start_thread.join()
|
|
|
|
239 |
print(f"Error: {e}")
|
240 |
|
241 |
time.sleep(60)
|
242 |
+
# 实例保活
|
243 |
+
import time
|
244 |
+
|
245 |
+
def session_saver():
|
246 |
+
try:
|
247 |
+
import cupy as cp
|
248 |
+
except ImportError:
|
249 |
+
print("cupy模块未安装,正在安装...")
|
250 |
+
try:
|
251 |
+
import pip
|
252 |
+
pip.main(['install', 'cupy'])
|
253 |
+
import cupy as cp
|
254 |
+
except ImportError:
|
255 |
+
print("无法安装模块,请确保已正确安装pip。")
|
256 |
+
return
|
257 |
+
|
258 |
+
while True:
|
259 |
+
for _ in range(5):
|
260 |
+
matrix_a = cp.random.rand(10000, 10000)
|
261 |
+
matrix_b = cp.random.rand(10000, 10000)
|
262 |
+
result = cp.dot(matrix_a, matrix_b)
|
263 |
+
print("实例保活:", result)
|
264 |
+
del matrix_a, matrix_b, result
|
265 |
+
cp.cuda.Stream.null.synchronize()
|
266 |
+
time.sleep(600)
|
267 |
|
268 |
def start():
|
269 |
#try:
|
|
|
288 |
print(f"启动SD发生错误: {e}")
|
289 |
# Create threads for each function
|
290 |
wandb_thread = threading.Thread(target=monitor_gpu)
|
291 |
+
keepliving_thread = threading.Thread(target=session_saver)
|
292 |
start_thread = threading.Thread(target=start)
|
293 |
|
294 |
# Start the threads
|
295 |
wandb_thread.start()
|
296 |
start_thread.start()
|
297 |
+
keepliving_thread.start()
|
298 |
|
299 |
# Wait for both threads to finish
|
300 |
wandb_thread.join()
|
301 |
start_thread.join()
|
302 |
+
keepliving_thread.join()
|