[IronPython] The tale of a full HybridMapping and a not so tempfile

Martin (gzlist) gzlist at googlemail.com
Thu Oct 22 23:50:08 CEST 2009

I'm trying to complete some work getting a big project running on
IronPython, but hit an issue where everything in the test suite would
start failing after a certain point with errors along the lines of:

Traceback (most recent call last):
  File "C:\Program Files\IronPython 2.6\Lib\tempfile.py", line 444, in
    (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
  File "C:\Program Files\IronPython 2.6\Lib\tempfile.py", line 228, in
    fd = _os.open(file, flags, 0600)
OSError: [Errno -2146233079] HybridMapping is full

After a long boring trek over the hills of ignorance that may have
been shorter if I'd seen that traceback first rather than other more
obscure ones, the root cause turned out to be a failure to clean up
temporary files. After IronPython has created 4096 of them and not
removed any afterwards everything involving filenos starts to
throwing. (As an aside, I wonder if using non-integer unique tokens
like Jython mightn't be a better approach).

The following issue tracker entry covers the tempfile issue:


However the bug report gets it a little wrong, the problem is not that
sys.platform == "win32" is false under IronPython, but rather that
os.name == "nt" is still true, but IronPython silently ignores the
os.O_TEMPORARY flag.

A trivial work around is:

    if sys.platform == "cli":
        os.name = "nty"
        import tempfile
        os.name = "nt"

However fixing this properly is also pretty simple, in
Src/IronPython.Modules/nt.cs the open function just needs to make sure
that File.Open gets passed DeleteOnClose. There may as well be a
FileOptionsFromFlags as per the existing FileModeFromFlags and
FileAccessFromFlags so that the following mappings are correct as

os.O_TEMPORARY -> FileOptions.DeleteOnClose -> FILE_FLAG_DELETE_ON_CLOSE
os.O_RANDOM -> FileOptions.RandomAccess -> FILE_FLAG_RANDOM_ACCESS
os.O_SEQUENTIAL -> FileOptions.SequentialScan -> FILE_FLAG_SEQUENTIAL_SCAN


More information about the Ironpython-users mailing list