如何获得Python中特定代码的内存以及我们的PC中可用的内存

发布于 2025-01-22 12:03:12 字数 996 浏览 0 评论 0原文

我想知道该代码消耗多少内存。也使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听不够的曲调 2025-01-29 12:03:12

如果使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文