3

编辑 2:对于那些想仔细查看代码的人,这里是: https ://github.com/pikzen/ffbookmark/blob/python-rewrite/ffbookmark.py

我在这里遇到了一些麻烦:每当我尝试将超过 204800 个字符写入文件时,python 都会引发 IOError。我在另一台计算机上尝试过,它以 768k 个字符崩溃。这是一个python问题,操作系统是否限制了什么?这是我正在使用的代码:

with open('out.json', 'w') as f:
    json.dump(items, f)

items是一个简单的字典。我从一个包含大约 800 个元素的 HTML 文件构建它。每个元素都是这样构建的:

bookmark = {}
            bookmark["title"] = link.contents[0]
            bookmark["id"] = id
            bookmark["parent"] = 5
            bookmark["dateAdded"] = 1
            bookmark["lastModified"] = 1
            bookmark["type"] = "text/x-moz-place"
            uri = link.get('href')
            # Shaarli's self links are totally messed up : ?xGRpkrp
            # But we can't simply oust links containing '?'s, because
            # php uses it, and pretty much everything does
            # however, if there's not dot, we can assume it's a 
            # Shaarli link.
            # If it's not, well too bad, false positive.
            if "?" in uri and not '.' in uri:
                bookmark['uri'] = "about:blank"
            else:
                bookmark['uri'] = uri
            id += 1

            try:
                # This line messes up when the end of the file has been reached
                # Rather than coding properly, let's just catch the exception
                desc = link.parent.next_sibling.next_sibling
                if desc and desc.name == "dd":
                    bookmark["annos"] = []
                    annos = {}
                    annos["name"] = "bookmarkProperties/description"
                    annos["flags"] = 0
                    annos["expires"] = 4
                    annos["mimeType"] = ""
                    annos["type"] = 3
                    annos["value"] = desc.contents[0]
                    bookmark["annos"].append(annos)

输出 :

IOError (Errno 27) : File too large

编辑:附加信息:Python 信息:

$ python --version
Python 2.7.3

使用的操作系统:

Linux Mint 13:限制:204.8kB

Debian 6.0:限制:768kB

4

1 回答 1

3

这不是 Python 错误,而是您正在写入的文件系统的限制,或者您的操作系统的等效(人为)限制。

用于ulimit -f检查您的文件大小限制。应该说unlimited。如果没有,您很可能需要编辑/etc/security/limits.conf. 您可以使用以下命令搜索有问题的配置:

grep fsize /etc/security/limits.conf /etc/security/limits.d/ -r

您可能还想检查您的文件系统quota或 grsecurity 限制。

最后,您可能需要检查mount以确保您希望挂载的文件系统就是您看到的那个。

于 2013-01-26T19:13:14.093 回答