Linux上的Python mmap'权限被拒绝' [英] Python mmap 'Permission denied' on Linux

查看:540
本文介绍了Linux上的Python mmap'权限被拒绝'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的文件,我正在尝试使用mmap打开文件,并且该文件被拒绝.我已经尝试过对os.open使用不同的标志和模式,但是对我来说不起作用.

I have a really large file I'm trying to open with mmap and its giving me permission denied. I've tried different flags and modes to the os.open but its just not working for me.

我在做什么错了?

>>> import os,mmap
>>> mfd = os.open('BigFile', 0)
>>> mfile = mmap.mmap(mfd, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
mmap.error: [Errno 13] Permission denied
>>> 

(使用内置的open()通过python docs示例工作,但似乎在读取和写入模式下都打开了文件的多个句柄.mmap.mmap方法所需的全部是文件数字,所以我不认为我需要创建一个file对象;因此,我尝试使用os.open())

(using the built in open() works via the python docs example, but it seems to open more than one handle to the file both in read & write mode. All i need for the mmap.mmap method is the file number, so I wouldn't assume i need to create a file object; hence my attempt at using os.open())

推荐答案

我认为这是一个标志问题,请尝试以只读方式打开:

I think its a flags issue, try opening as read only:

mfd = os.open('BigFile', os.O_RDONLY)

和mmap.mmap默认情况下会尝试映射读/写,因此仅将映射映射为:

and mmap.mmap by default tries to map read/write, so just map read only:

mfile = mmap.mmap(mfd, 0, prot=mmap.PROT_READ)

这篇关于Linux上的Python mmap'权限被拒绝'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆