2010-11-19 13 views
6

EDIT: A sugerencia de JF Sebastián, puedo conseguir el mismo error mucho más simple:Python "IOError: [Errno 22] El argumento no válido" cuando se utiliza cPickle escribir gran variedad a la unidad de red

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

Tenga en cuenta que C: es una unidad local y Z: es una unidad de red.

pregunta original:

Python 2.6.4 en Windows XP se bloquea si uso cPickle para escribir un archivo más grande que ~ 67 MB a nuestra unidad de red (ReadyNAS Pro Edition Pioneer). Me gustaría poder guardar archivos grandes. ¿Es este un problema conocido? ¿Hay alguna solución?

La siguiente secuencia de comandos produce un accidente:

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 

He aquí los pasos que tomo para producir un accidente en el indicador 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: es la unidad de disco duro local del equipo. Z: es nuestro almacenamiento conectado a la red.

+0

Nota: array 'numpy' puede conservar en vinagre en sí:' a.dump'. – jfs

+1

¿'abierto (r'z: \ test.bin ',' wb '). Write (' a '* 67080064)' funciona? – jfs

+0

¡Excelente pregunta! Una forma mucho más simple de reproducir el mismo error. Voy a editar la pregunta. – Andrew

Respuesta

15

Creo que el problema está relacionado con: http://support.microsoft.com/default.aspx?scid=kb;en-us;899149

... así, sólo tratar: abierta (r'z: \ test.bin', 'w + b') escribir (. 'Una '* 67080064)

* Nota del argumento: 'w + b'

+0

¡Gracias! Esto funciona. – Andrew

+0

abierto (r'z: \ test.bin ',' wb '). Write (' a '* 67076096) falla, wheras abierto (r'z: \ test.bin', 'wb'). Write ('a '* 67076095) no falla, pero es demasiado pequeño. Por suerte, abrir (r'z: \ test.bin ',' w + b '). Write (' a '* 67076096) funciona! – Andrew

+0

No funciona para Mac OS X. El parche que corrige esto está bajo revisión durante mucho tiempo https://bugs.python.org/issue24658 – Serendipity

Cuestiones relacionadas