python - 使用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
解决方案
推荐阅读
- scala - 在具有给定上下文绑定的嵌套列表中键入擦除
- matlab - 根据在其他矩阵上设置的条件在 matlab 中索引矩阵
- mysql - 使用 CSV 导入更新 mySQL 表中的一列
- react-native - 为什么登录后我的 react-navigation 路由无法正常工作?
- pandas - yaxis中的数字在matplotlib中没有按顺序排列
- c++ - std::complex operator* 在某些编译器上的性能缓慢
- python - 如何在 Google 电子表格中添加值
- java - 使用 Hibernate 执行 CRUD 操作时发生错误
- c++ - 保存迷宫的图像
- html - 访问类 HTML 中的特定元素