Unable to unlink file

Issue #191 resolved
Former user created an issue

This is a repeat of issue #132, but I also am getting an "unable to unlink" error when using Windows 7, Python 2.7 64 bit, and R 3.0.2.

Even trying to manually delete the file doesn't work as it is locked by a process. According to some unlocker software, it is locked by python.

In robject.py, I am able to confirm that the file is closed by inserting a print(tmpf.closed) after the tmpf.close() command. However, there must be a floating reference to the file somewhere (probably in the rpy2 C library code) that is causing this error.

Any suggestions?

Comments (3)

  1. Unknown Name

    I am able to get the problem to go away when I add the self.__close(tmp) line in robject.py as shown below. I think there's a file handle on the R side of things pointing to that temporary file and closing it seems to take care of the issue. Perhaps this is a needed change?

    if sys.platform == 'win32':
                s = tmpf.readlines()
                    del tmpf
                except WindowsError:
                    if os.path.exists(tfname):
                        print 'Unable to unlink tempfile %s' % tfname
                s = str.join(os.linesep, s)
  2. Laurent Gautier

    The change was added with a1a8364e9a82. Can anyone check whether the problem is solved ?

    I'd also be happy if something could check whether the unit tests are covering this on Windows.

  3. Log in to comment