Skip to content

Commit

Permalink
自动清理内存
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroWolf233 committed Aug 30, 2024
1 parent 1e2af0b commit 6bfe40e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import time
from concurrent.futures import ThreadPoolExecutor
import gc

# 定义请求函数
def send_request(url, headers, rest, i):
Expand All @@ -22,6 +23,11 @@ def send_request(url, headers, rest, i):
except requests.exceptions.RequestException as e:
print(f"请求 {i + 1} 失败,发生异常: {e}\n\n"+"-"*100+"\n")

finally:
# 手动删除不再需要的对象
del response
gc.collect() # 强制执行垃圾回收

# 每次请求后休息指定时间
time.sleep(int(rest))

Expand Down

0 comments on commit 6bfe40e

Please sign in to comment.