有没有办法跟踪python进程来检查文件被打开的位置。我lsof在运行过程中使用时打开了太多文件,但我不确定它们是在哪里打开的。
ls /proc/$pid/fd/ | wc -l
Run Code Online (Sandbox Code Playgroud)
我怀疑我使用的库之一可能没有正确处理文件。有没有办法准确地隔离正在打开文件的python代码中的哪一行?
在我的代码中,我使用 3rd 方库来处理数千个媒体文件,由于它们处于打开状态,我收到了错误
OSError: [Errno 24] Too many open files
Run Code Online (Sandbox Code Playgroud)
运行几分钟后。现在我知道提高打开文件的限制是一个选项,但这只会将错误推到以后的时间点。
我需要访问文件夹中的所有图像并将其存储在矩阵中.我能够使用matlab完成它,这里是代码:
input_dir = 'C:\Users\Karim\Downloads\att_faces\New Folder';
image_dims = [112, 92];
filenames = dir(fullfile(input_dir, '*.pgm'));
num_images = numel(filenames);
images = [];
for n = 1:num_images
filename = fullfile(input_dir, filenames(n).name);
img = imread(filename);
img = imresize(img,image_dims);
end
Run Code Online (Sandbox Code Playgroud)
但我需要使用python来完成它,这是我的python代码:
import Image
import os
from PIL import Image
from numpy import *
import numpy as np
#import images
dirname = "C:\\Users\\Karim\\Downloads\\att_faces\\New folder"
#get number of images and dimentions
path, dirs, files = os.walk(dirname).next()
num_images = len(files)
image_file = "C:\\Users\\Karim\\Downloads\\att_faces\\New folder\\2.pgm"
im = Image.open(image_file)
width, height …Run Code Online (Sandbox Code Playgroud)