如何获得Python中特定代码的内存以及我们的PC中可用的内存
我想知道该代码消耗多少内存。也使用Python代码在我的PC中可用的内存。该怎么办?
这是我的代码:
from moviepy.editor import *
import os
import glob
from natsort import natsorted
import datetime
import time
import shutil
from concurrent.futures import ThreadPoolExecutor
def fast(path, thread_name):
if os.path.splitext(path)[1] == '.mp4':
print("Start : " + str(thread_name) + " - " + str(datetime.datetime.now()))
clip = (VideoFileClip(path).fx(vfx.speedx, 5))
clip.to_videofile('G:/Ocsid Technologies/BUILDERS/Builder-1/Project-1/Converted Videos/' +
thread_name + '.mp4', codec='libx264')
time.sleep(3)
shutil.move(path, "G:/Ocsid Technologies/BUILDERS/Builder-1/Project-1/Original Videos/")
print("End : " + str(thread_name) + " - " + str(datetime.datetime.now()))
with ThreadPoolExecutor(5) as pool:
for i, filename in enumerate(glob.glob("G:/Ocsid Technologies/BUILDERS/Builder-1/Project-1/Raw
Videos/*.mp4"), 1):
pool.submit(fast, filename, f"t{i}")
I want to know how much memory this code consumes . Also available memory in my pc using a python code. What has to be done?
Here is my code :
from moviepy.editor import *
import os
import glob
from natsort import natsorted
import datetime
import time
import shutil
from concurrent.futures import ThreadPoolExecutor
def fast(path, thread_name):
if os.path.splitext(path)[1] == '.mp4':
print("Start : " + str(thread_name) + " - " + str(datetime.datetime.now()))
clip = (VideoFileClip(path).fx(vfx.speedx, 5))
clip.to_videofile('G:/Ocsid Technologies/BUILDERS/Builder-1/Project-1/Converted Videos/' +
thread_name + '.mp4', codec='libx264')
time.sleep(3)
shutil.move(path, "G:/Ocsid Technologies/BUILDERS/Builder-1/Project-1/Original Videos/")
print("End : " + str(thread_name) + " - " + str(datetime.datetime.now()))
with ThreadPoolExecutor(5) as pool:
for i, filename in enumerate(glob.glob("G:/Ocsid Technologies/BUILDERS/Builder-1/Project-1/Raw
Videos/*.mp4"), 1):
pool.submit(fast, filename, f"t{i}")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果使用Visual Studio代码,则可以添加两个中断点(代码的开始和结尾),并使用诊断工具窗口可以获取此数据。
Visual Studio Code上的诊断工具
Visual Studio代码上的诊断工具
下面的链接(西班牙语)下面解释了
https://learn.microsoft.com/es-es-es-es/visalstudio/profiling/memory-usage-usage/memory-usage?view==vs-20222
我希望它有帮助
If you use Visual Studio Code, you can add two interruption points (beginning and end of the code) and using the Diagnostic Tools window you can get this data.
Diagnostic tools on Visual Studio Code
Diagnostic tools on Visual Studio Code
Below a link (in Spanish) where it is explained
https://learn.microsoft.com/es-es/visualstudio/profiling/memory-usage?view=vs-2022
I hope it helps