@khaledhosny I am not sure, but maybe we can avoid closing and reopening by passing the appropiate flags to ``mkstemp``using the ``text`` parameter: http://docs.python.org/2/library/tempfile.html#tempfile.mkstemp