2010-11-19 20 views
6

EDIT: Tại gợi ý của JF Sebastian, tôi có thể nhận được lỗi cùng nhiều đơn giản hơn:Python "IOError: [Errno 22] lập luận không hợp lệ" khi sử dụng cPickle viết mảng lớn mạng ổ

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]: 

Lưu ý rằng C: là ổ đĩa cục bộ và Z: là ổ đĩa mạng.

ORIGINAL HỎI:

Python 2.6.4 trên Windows XP bị treo nếu tôi sử dụng cPickle để viết một tập tin lớn hơn ~ 67 MB đến ổ đĩa mạng của chúng tôi (ReadyNAS Pro Pioneer edition). Tôi muốn có thể nhặt các tệp lớn. Đây có phải là một vấn đề được biết đến? Có cách giải quyết nào không?

Các kịch bản sau đây tạo ra một vụ tai nạn:

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 

Dưới đây là các bước tôi đi để tạo ra một vụ tai nạn tại dấu nhắc 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: là ổ đĩa cứng cục bộ trên máy tính này. Z: là bộ nhớ được kết nối mạng của chúng tôi.

+0

Lưu ý: mảng 'numpy' có thể tự chọn:' a.dump'. – jfs

+1

Có 'mở (r'z: \ test.bin ',' wb '). Viết (' a '* 67080064)' làm việc? – jfs

+0

Câu hỏi hay! Một cách đơn giản hơn nhiều để tái tạo cùng một lỗi. Tôi sẽ chỉnh sửa câu hỏi. – Andrew

Trả lời

15

tôi tin rằng các vấn đề có liên quan đến: http://support.microsoft.com/default.aspx?scid=kb;en-us;899149

... do đó, chỉ cần thử: mở (r'z: \ test.bin', 'w + b') viết (. 'Một '* 67080064)

* Lưu ý đối số:' w + b '

+0

Cảm ơn bạn! Những công việc này. – Andrew

+0

mở (r'z: \ test.bin ',' wb '). Ghi (' a '* 67076096) không thành công, mở cửa sổ (r'z: \ test.bin', 'wb'). '* 67076095) không thành công, nhưng quá nhỏ. May mắn thay, mở (r'z: \ test.bin ',' w + b ') viết (' a '* 67076096) hoạt động! – Andrew

+0

Không hoạt động đối với Mac OS X. Bản vá sửa lỗi này đang được xem xét trong một thời gian dài https://bugs.python.org/issue24658 – Serendipity

Các vấn đề liên quan