PascalLesage / presamples

Package to write, load, manage and verify numerical arrays, called presamples.
BSD 3-Clause "New" or "Revised" License
14 stars 11 forks source link

campaigns.db prevents brightway project directory from being deleted #42

Open pjamesjoyce opened 6 years ago

pjamesjoyce commented 6 years ago
projects.delete_project(delete_dir=True)
projects.delete_project('my_project', delete_dir=True)

and

projects.purge_deleted_directories()

fail with error:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\pjjoyce\\AppData\\Local\\pylca\\Brightway3\\my_project.8eb9cc4510ff31ac37ca85f9bbee44c1\\campaigns.db'

I think campaigns are a presamples thing right?

Shutting down all running instances of brightway and restarting a fresh brightway instance allows you to delete/purge project directories. But deleting only works if its the first command you use in a new brightway session

Steps to reproduce:

from brightway2 import *
projects.set_current('my_project') # in the create new project sense of set_current()
projects.delete_project(delete_dir=True)
PascalLesage commented 6 years ago

Indeed this is due to presamples, and this is a problem I've had too (but failed to report - thanks).
The problem database, campaigns.bd, is a SubstitutableDatabase instance. SubstitutableDatabase is defined by @cmutel in bw2data here, and is used in Brightway2 without any problems (e.g. for the ProjectManager and the ParameterManager).
So what needs to be done is figure out why this substitutable database stays connected. Its a peewee question I haven't had time to look into yet, and will gladly accept any fix.

cmutel commented 6 years ago

I think presamples is a red herring - it looks like Windows won't let you delete a file is another process has an open file handle. The key is in the error message: The process cannot access the file because it is being used by another process. Any chance that another notebook or ipython process is using the same project? I can't open my Windows VM to test this, but it isn't a problem on *nix (though perhaps it should be...)