为什么我编的录频程序那么费内存?
每到加载gif时就黑屏
代码如下:
if __name__=='__main__':
from tkinter import messagebox as mess
from tkinter.ttk import Button as Btt
from tkinter import Tk
from tkinter import Button as Btk
from sys import exit as exit_
import time
from PIL import ImageGrab as g
from pynput import keyboard as k
from threading import Thread
def save():
print('save go')
v[0].save('giffile.gif',format='gif',save_all=True,append_images=v[1:],duration=60)
print('1')
def quit():
print('END')
win.destroy()
exit_()#退出程序
print(2)
def go():
win.destroy()
def quit_l(k):
print(k)
print('qui_l.go')
if k==GJ_key.ctrl_l:
print('按下ctrl')
f_e=0
thsave.start()
def go():
print('Go!Go!Go!')
while f_e!=0:
v.append(g.grab())
time.sleep(0.03)
global v
v=[]
global f_e
f_e=1
f1=0
global thsave
global GJ_key
GJ_key=k.Key
thgo=Thread(target=go)
thsave=Thread(target=save)
pnl=k.Listener(on_press=quit_l)
#当按下某键启动quit函数,松开某键启动puit_f函数
pnl.start()#开始检测
thgo.start()
print(3)
win=Tk()
win.overrideredirect(True)
win.resizable(0,0)
win.geometry('200x100+0+0')
Btk(win,text='退出',\
bg='red',\
fg='black',\
width=5,\
command=quit).pack(side='left',fill='y')
Btt(win,text='开始',command=go).pack(side='left',fill='both')
win.mainloop()
当按下ctrl键时停止录频并加载gif,为什么我的就是加载不出来?而且加载时内存占用变得非常高,不断上升,从20%到30%,50%,达到95%,我的电脑直接黑屏,我蒙了。以前还很流畅,windows报错说某东西损坏就加载不了了。是不是是我的程序问题?如是,请指出,谢谢。
(我截不了屏,当内存占用率达到将近100%时不可能截屏了,直接黑屏,所以无法提供图片)