gpt4 book ai didi

使用 cPickle 将大型数组写入网络驱动器时出现 Python "IOError: [Errno 22] Invalid argument"

转载 作者:太空狗 更新时间:2023-10-29 22:08:29 24 4
gpt4 key购买 nike

编辑:在 J. F. Sebastian 的建议下,我可以更简单地得到同样的错误:

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

Welcome to pylab, a matplotlib-based Python environment.
For more information, type 'help(pylab)'.

In [1]: open(r'c:\test.bin', 'wb').write('a'*67076095)

In [2]: open(r'c:\test.bin', 'wb').write('a'*67076096)

In [3]: open(r'z:\test.bin', 'wb').write('a'*67076095)

In [4]: open(r'z:\test.bin', 'wb').write('a'*67076096)
---------------------------------------------------------------------------
IOError Traceback (most recent call last)

C:\Documents and Settings\User\<ipython console> in <module>()

IOError: [Errno 22] Invalid argument

In [5]:

请注意,C: 是本地驱动器,Z: 是网络驱动器。

原始问题:

如果我使用 cPickle 将大于 ~67 MB 的文件写入我们的网络驱动器(ReadyNAS Pro 先锋版),Windows XP 上的 Python 2.6.4 会崩溃。我希望能够 pickle 大文件。这是一个已知问题吗?有解决方法吗?

以下脚本会导致崩溃:

import cPickle, numpy

a = numpy.zeros(8385007)
print "Writing %i bytes..."%(a.nbytes)
cPickle.dump(a, open('test_a.pkl', 'wb'), protocol=2)
print "Successfully written."

b = numpy.zeros(8385008)
print "Writing %i bytes..."%(b.nbytes)
cPickle.dump(b, open('test_b.pkl', 'wb'), protocol=2) ##Crashes on a network drive
print "Successfully written." ##Doesn't crash on a non-network drive

以下是我在 ipython 提示符下产生崩溃的步骤:

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

Welcome to pylab, a matplotlib-based Python environment.
For more information, type 'help(pylab)'.

In [1]: pwd
Out[1]: 'C:\\Documents and Settings\\User'

In [2]: run test
Writing 67080056 bytes...
Successfully written.
Writing 67080064 bytes...
Successfully written.

In [3]: cd Z:
Z:\

In [4]: pwd
Out[4]: 'Z:\\'

In [5]: run 'C:\\Documents and Settings\\User\\test'
Writing 67080056 bytes...
Successfully written.
Writing 67080064 bytes...
---------------------------------------------------------------------------
IOError Traceback (most recent call last)

C:\Documents and Settings\User\test.py in <module>()
8 b = numpy.zeros(8385008)
9 print "Writing %i bytes..."%(b.nbytes)
---> 10 cPickle.dump(b, open('test_b.pkl', 'wb'), protocol=2)
11 print "Successfully written."
12

IOError: [Errno 22] Invalid argument
WARNING: Failure executing file: <C:\\Documents and Settings\\User\\test.py>

In [6]:

C: 是机器上的本地硬盘。 Z: 是我们的网络附加存储。

最佳答案

我认为问题与以下方面有关: http://support.microsoft.com/default.aspx?scid=kb;en-us;899149

...所以,试试看:打开(r'z:\test.bin','w+b').write('a'*67080064)

*注意参数:'w+b'

关于使用 cPickle 将大型数组写入网络驱动器时出现 Python "IOError: [Errno 22] Invalid argument",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4226941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com