Map*_*ofu 5 python bash operating-system docker oserror
问题:
我有一个文件夹(json_folder_large),其中包含 200, 000 多个 json 文件,另一个文件夹(json_folder_small),其中包含 10, 000 个 json 文件。
import os
lst_file = os.listdir("tmp/json_folder_large") # this returns an OSError
OSError: [Errno 5] Input/output error: 'tmp/json_folder_large'
Run Code Online (Sandbox Code Playgroud)
当我将 listdir 与目录路径一起使用时,出现 OSError 。我确信路径没有问题,因为我可以对其他文件夹执行相同的操作,而不会出现此 OSError。
lst_file = os.listdir("tmp/json_folder_small") # no error with this
Run Code Online (Sandbox Code Playgroud)
环境:
上面的问题是docker 镜像作为 pycharm 解释器。
当解释器是conda env时,没有错误。
我能看到的唯一区别是,在我的 docker/preferences/resources/advanced 中,我设置了 4 个 CPU(最大为 6)和 32GB 内存(最大为 64)。
我尝试过:(在docker下)
1.使用Pathlib
import pathlib
pathlib.Path('tmp/json_folder_large').iterdir() # this returns a generator <generator object Path.iterdir at 0x7fae4df499a8>
for x in pathlib.Path('tmp/json_folder_large').iterdir():
print("hi")
break
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python3.7/pathlib.py", line 1074, in iterdir for name in self._accessor.listdir(self):
OSError: [Errno 5] Input/output error: 'tmp/json_folder_large'
Run Code Online (Sandbox Code Playgroud)
2.使用os.scandir
os.scandir("tmp/json_folder_large") # this returns a generator <posix.ScandirIterator object at 0x7fae4c48f510>
for x in os.scandir("tmp/json_folder_large"):
print("hi")
break
Traceback (most recent call last):
File "<input>", line 1, in <module>
OSError: [Errno 5] Input/output error: 'tmp/json_folder_large'
Run Code Online (Sandbox Code Playgroud)
3.将pycharm终端连接到docker容器,然后执行ls
docker exec -it 21aa095da3b0 bash
cd json_folder_large
ls
Run Code Online (Sandbox Code Playgroud)
然后我得到一个错误(当终端未连接到 docker 容器时,上面的代码不会引发错误!!!!!)
ls: reading directory '.': Input/output error
Run Code Online (Sandbox Code Playgroud)
问题:
提前致谢。