Home > other >  Python loop script memory is more and more big how to solve
Python loop script memory is more and more big how to solve

Time:10-05

Write a script in python,
Used while the circulation of the True,
Basic content is detection of a certain point in the image, color, whether a particular color, if is you,
When running, open the task manager, you can see the Python. Exe memory is more and more big, the
Over a period of time, the script doesn't work, stuck,
In a multithreaded way, also can't solve,
Do you have any good way?

CodePudding user response:

The following is the code:
#! The/usr/bin/env python
# - * - coding: utf-8 - * -
# coding=utf-8

"" "
@ the author: Li Tian,
@ contact: 694317828 @qq.com
@ software: pycharm
@ file: hunshi_test3. Py
@ time: 2019/1/12 he
@ desc: soul ten test 3
"" "

The import pyautogui as PTG
The import time
The import of gc
The from threading import Thread
The import yinyangshi. The parameters as par
The import yinyangshi. Setting the as sett
The from yinyangshi. Baigui_test import click_motion just_motion, click_small
The from yinyangshi. Random_file import *
The import yinyangshi. Baigui_test as ghost1
The import yinyangshi. Fight_for_boys as FFB


Def yaoqing1 () :
"" "automatic receive invitation and invited "","
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 () :
"" "automatic receive invitation and invited "","
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 () :
# main loop
While sett. State:
# invited to accept others, just click on the settlement interface
# monitoring victory or failure
Sett. Hunshi_win=PTG. PixelMatchesColor (par. Hunshi_loc [0], par. Hunshi_loc [1], par. Hunshi_color)

If sett. Hunshi_win and sett. State:
# end of combat
# click to receive rewards
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 () :
# main loop
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:
# to receive rewards
# click return
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)

Soul # 10 brush out
Print (' to complete the first '+ STR (sett. Number) +' ten times soul,,,)

Time. Sleep (pause_time ())


Def the main () :
The gc. The 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. tart ()
For j in threads_list:
J.j oin ()


If __name__=="__main__ ':
The main ()

CodePudding user response:

The fastest solution is to make python running for a period of time, turn off automatically, restart again, after the restart then the last time you can run, of course

CodePudding user response:

The import of gc
Gc. Collect ()
  • Related