首页 > 解决方案 > 使用python在计算机中运行程序后台时如何优化数据、内存和内存?

问题描述

我正在制作一个关于 python 3.9 中的欢迎消息的项目,当我启动计算机时,这个项目正在我的计算机上运行后台,它将运行脚本。我倾向于在这个项目中添加更多的功能,让它像一个助手来帮助我搜索东西,创建和写入文件,但不幸的是,我对这个项目有一个问题,数据使用是(30%)、存储和内存(60%) 在我的项目中,它太高了,电脑受不了,所以当我启动电脑时,我的项目会运行几秒钟然后中断,然后我的任务栏或桌面屏幕会消失或出现蓝色-红色。希望有人可以帮助我修复它。

我的笔记本电脑是 Dell Inspiron 14 N4050(2011),它的配置是:

核心 I3-2330 @2.20 HZ

6 GB 内存和 100 GB SSD

谢谢你的帮助!

这是我的代码

import subprocess
import pyautogui
import time
import pandas as pd
import datetime
import os
import pyttsx3
import win32gui, win32con

#This is using to hide the terminal when the script is running background.
hide = win32gui.GetForegroundWindow()
win32gui.ShowWindow(hide , win32con.SW_HIDE)
#---------------------------------------------------------

user = "Tom" #your name
# Robot speech
# Jarvis_brain = speak
# Jarvis_mouth = engine
assistant= "Jarvis" # Iron man Fan
Jarvis_mouth = pyttsx3.init()
Jarvis_mouth.setProperty("rate", 140)
voices = Jarvis_mouth.getProperty("voices")
Jarvis_mouth.setProperty("voice", voices[1].id)


def Jarvis_brain(audio):
    print("Jarvis: " + audio)
    Jarvis_mouth.say(audio)
    Jarvis_mouth.runAndWait()


# Welcome message

def greet():
    time.sleep(10)
    hour=datetime.datetime.now().hour
    if hour>=0 and hour<12:
        Jarvis_brain("Start the system, your AI personal assistant Jarvis")
        Jarvis_brain(f"Hello, Good Morning {user}")
        print("Hello,Good Morning")
    elif hour>=12 and hour<18:
        Jarvis_brain("Start the system, your AI personal assistant Jarvis")
        Jarvis_brain(f"Hello, Good Afternoon {user}")
        print("Hello, Good Afternoon")
    else:
        Jarvis_brain("Start the system, your AI personal assistant Jarvis")
        Jarvis_brain(f"Hello, Good Evening {user}")
        print("Hello,Good Evening")
greet()        

os.system("python op1.pyw")# This file is for assistant and other features

标签: pythonpython-3.xpython-3.9

解决方案


推荐阅读