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':
                self.__sink()
                s = tmpf.readlines()
                tmpf.close()
                self.__close(tmp)
                try:
                    del tmpf
                    os.unlink(tfname)
                except WindowsError:
                    if os.path.exists(tfname):
                        print 'Unable to unlink tempfile %s' % tfname
                s = str.join(os.linesep, s)
    
  2. Log in to comment