用python寫了一個腳本。
用的是while True的回圈。
基本內容是一直檢測影像中某一個點的顏色,是否是某個顏色,如果是就進行操作。
運行的時候,打開任務管理器,可以看到Python.exe的記憶體越來越大。
過一段時間,腳本就不起作用了,卡住了。
用了多執行緒的方式,也沒法解決。
請問有什么好的辦法嗎。
uj5u.com熱心網友回復:
以下是代碼:#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# coding=utf-8
"""
@author: Li Tian
@contact: [email protected]
@software: pycharm
@file: hunshi_test3.py
@time: 2019/1/12 20:20
@desc: 魂十測驗3
"""
import pyautogui as ptg
import time
import gc
from threading import Thread
import yinyangshi.parameters as par
import yinyangshi.setting as sett
from yinyangshi.baigui_test import click_motion, just_motion, click_small
from yinyangshi.random_file import *
import yinyangshi.baigui_test as ghost1
import yinyangshi.fight_for_boys as ffb
def yaoqing1():
"""接收邀請和自動邀請"""
while sett.state:
sett.yaoqing1 = ptg.pixelMatchesColor(par.hs_yaoqing_loc[0], par.hs_yaoqing_loc[1], par.hs_yaoqing_color)
if sett.yaoqing1:
click_small(par.hs_yaoqing_loc)
time.sleep(pause_time() + 2)
time.sleep(pause_time())
def yaoqing2():
"""接收邀請和自動邀請"""
while sett.state:
sett.yaoqing2 = ptg.pixelMatchesColor(par.hunshi_yaoqing_loc[0], par.hunshi_yaoqing_loc[1], par.hunshi_yaoqing_color)
if sett.yaoqing2:
click_small(par.hunshi_yaoqing_loc)
time.sleep(pause_time() + 2)
time.sleep(pause_time())
def run1():
# 主回圈
while sett.state:
# 接受別人邀請的人,只需要點擊結算界面
# 監測勝利還是失敗
sett.hunshi_win = ptg.pixelMatchesColor(par.hunshi_loc[0], par.hunshi_loc[1], par.hunshi_color)
if sett.hunshi_win and sett.state:
# 戰斗結束
# 點擊領取獎勵
click_motion(par.hunshi_loc)
time.sleep(pause_time())
click_motion(par.hs_jiesuan_loc)
time.sleep(pause_time()+2)
time.sleep(pause_time())
def run2():
# 主回圈
while sett.state:
sett.hs_jiesuan = ptg.pixelMatchesColor(par.hs_jiesuan_loc[0], par.hs_jiesuan_loc[1], par.hs_jiesuan_color)
if sett.hs_jiesuan and sett.state:
# 領取獎勵
# 點擊回傳
time.sleep(pause_time()+2)
sett.number += 1
click_motion(par.hs_jiesuan_loc)
time.sleep(pause_time())
click_motion(par.hs_jiesuan_loc)
time.sleep(pause_time())
click_motion(par.hs_jiesuan_loc)
time.sleep(pause_time()+3)
# 魂十刷完了
print('完成第' + str(sett.number) + '次魂十。。。')
time.sleep(pause_time())
def main():
gc.enable()
threads_list = []
t1 = Thread(target=run1)
threads_list.append(t1)
t2 = Thread(target=run2)
threads_list.append(t2)
t3 = Thread(target=yaoqing2)
threads_list.append(t3)
t4 = Thread(target=yaoqing1)
threads_list.append(t4)
th = Thread(target=ghost1.hook)
threads_list.append(th)
t5 = Thread(target=ffb.run2)
threads_list.append(t5)
for i in threads_list:
i.start()
for j in threads_list:
j.join()
if __name__ == '__main__':
main()
uj5u.com熱心網友回復:
最快的解決辦法就是讓python運行一段時間,自動關掉,再重啟,當然重啟后可以接著你上次的運行uj5u.com熱心網友回復:
import gcgc.collect()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/112305.html
上一篇:python問題
下一篇:求大神幫幫忙
