tempfile.mkstemp gives bad file descriptor?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

tempfile.mkstemp gives bad file descriptor?

Slide-2
For some reason, I am now getting the following error when running the
unit tests for the csv module.

======================================================================
ERROR: test_write_simple_dict (__main__.TestDictFields)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
nPython\27\Lib\test\test_csv.py", line 598, in test_write_simple_dict
    fd, name = tempfile.mkstemp()
OSError: [Errno 9] Bad file descriptor

----------------------------------------------------------------------
Ran 80 tests in 2.774s

FAILED (errors=1)
Traceback (most recent call last):
  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
nPython\27\Lib\test\test_csv.py", line 1054, in <module>
  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
nPython\27\Lib\test\test_csv.py", line 1049, in test_main
  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
nPython\27\Lib\test\test_support.py", line 1078, in run_unittest
  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
nPython\27\Lib\test\test_support.py", line 1061, in _run_suite
test.test_support.TestFailed: Traceback (most recent call last):
  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
nPython\27\Lib\test\test_csv.py", line 598, in test_write_simple_dict
    fd, name = tempfile.mkstemp()
OSError: [Errno 9] Bad file descriptor


The error occurs on the following code

fd, name = tempfile.mkstemp()
fileobj = io.open(fd, 'w+b')

There are several other occurences of tempfile.mkstemp and then
os.fdopen. This is the only one that uses io.open. I am not sure why
they use io.open in this case. If I replace the io.open with
os.fdopen, it works as expected. At the point in PythonFile where it
calls objMapping.GetObjectFromId, there is nothing in the mapping
dictionary, it is completely empty.

I am unfamiliar with all the internals still, but I will try and
discover what is going on. Seems like this could be a bug.

Thanks,

slide

--
slide-o-blog
http://slide-o-blog.blogspot.com/
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: tempfile.mkstemp gives bad file descriptor?

Slide-2
On Sat, Mar 5, 2011 at 9:24 PM, Slide <[hidden email]> wrote:

> For some reason, I am now getting the following error when running the
> unit tests for the csv module.
>
> ======================================================================
> ERROR: test_write_simple_dict (__main__.TestDictFields)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
> nPython\27\Lib\test\test_csv.py", line 598, in test_write_simple_dict
>    fd, name = tempfile.mkstemp()
> OSError: [Errno 9] Bad file descriptor
>
> ----------------------------------------------------------------------
> Ran 80 tests in 2.774s
>
> FAILED (errors=1)
> Traceback (most recent call last):
>  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
> nPython\27\Lib\test\test_csv.py", line 1054, in <module>
>  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
> nPython\27\Lib\test\test_csv.py", line 1049, in test_main
>  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
> nPython\27\Lib\test\test_support.py", line 1078, in run_unittest
>  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
> nPython\27\Lib\test\test_support.py", line 1061, in _run_suite
> test.test_support.TestFailed: Traceback (most recent call last):
>  File "C:\Users\acearl\Code\IronLanguages\External.LCA_RESTRICTED\Languages\Iro
> nPython\27\Lib\test\test_csv.py", line 598, in test_write_simple_dict
>    fd, name = tempfile.mkstemp()
> OSError: [Errno 9] Bad file descriptor
>
>
> The error occurs on the following code
>
> fd, name = tempfile.mkstemp()
> fileobj = io.open(fd, 'w+b')
>
> There are several other occurences of tempfile.mkstemp and then
> os.fdopen. This is the only one that uses io.open. I am not sure why
> they use io.open in this case. If I replace the io.open with
> os.fdopen, it works as expected. At the point in PythonFile where it
> calls objMapping.GetObjectFromId, there is nothing in the mapping
> dictionary, it is completely empty.
>
> I am unfamiliar with all the internals still, but I will try and
> discover what is going on. Seems like this could be a bug.
>
> Thanks,
>
> slide
>


This looks like its because nt.open calls

PythonContext.GetContext(context).FileManager.AddToStrongMapping(PythonFile.Create(context,
fs, filename, mode2))

which adds the file to the fileMapping object

but io.open does

fio = new FileIO(context, fd, mode, closefd);

this calls

FileIO file = (FileIO)pc.FileManager.GetObjectFromId(fd);

which looks in objectMapping.

os(nt).fdopen does

if (pythonContext.FileManager.TryGetFileFromId(pythonContext, fd, out pf)) {
                return pf;
}

first before looking in the objectMapping, which is why it works for os.fdopen.
_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com