joblib: Windows permission error

I have a permission error while using Parallel(n_jobs=2) on windows:

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\site-packages\joblib\disk.py:122: UserWarning: Unable to delete folder xxxx\AppData\Local\Temp\joblib_memmapping_folder_15364_9553521538 after 5 tentatives.
  .format(folder_path, RM_SUBDIRS_N_RETRY))
---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
~\Desktop\all_repos\gitlab_projects\wireless_optim\code\complete_experiment.py in <module>()
    422         simulator_data = np.concatenate([simulator_data, new_simulator_data],
    423                                         axis=0)
--> 424         n_admissible_actions.append(n_admissible_actions_d)
    425
    426 if 0:

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\site-packages\joblib\parallel.py in __exit__(self, exc_type, exc_value, traceback)
    664
    665     def __exit__(self, exc_type, exc_value, traceback):
--> 666         self._terminate_backend()
    667         self._managed_backend = False
    668

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\site-packages\joblib\parallel.py in _terminate_backend(self)
    694     def _terminate_backend(self):
    695         if self._backend is not None:
--> 696             self._backend.terminate()
    697
    698     def _dispatch(self, batch):

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\site-packages\joblib\_parallel_backends.py in terminate(self)
    528             # in latter calls but we free as much memory as we can by deleting
    529             # the shared memory
--> 530             delete_folder(self._workers._temp_folder)
    531             self._workers = None
    532

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\site-packages\joblib\disk.py in delete_folder(folder_path, onerror)
    113             while True:
    114                 try:
--> 115                     shutil.rmtree(folder_path, False, None)
    116                     break
    117                 except (OSError, WindowsError):

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\shutil.py in rmtree(path, ignore_errors, onerror)
    492             os.close(fd)
    493     else:
--> 494         return _rmtree_unsafe(path, onerror)
    495
    496 # Allow introspection of whether or not the hardening against symlink

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\shutil.py in _rmtree_unsafe(path, onerror)
    387                 os.unlink(fullname)
    388             except OSError:
--> 389                 onerror(os.unlink, fullname, sys.exc_info())
    390     try:
    391         os.rmdir(path)

~\AppData\Local\Continuum\anaconda3\envs\wireless_optim\lib\shutil.py in _rmtree_unsafe(path, onerror)
    385         else:
    386             try:
--> 387                 os.unlink(fullname)
    388             except OSError:
    389                 onerror(os.unlink, fullname, sys.exc_info())

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'xxxx\\AppData\\Local\\Temp\\joblib_memmapping_folder_15364_9553521538\\15364-3031207306352-94b02d62d9b44d709a9a405235589ead.pkl'

Is this related to the fact that removing a memmap can fail on Windows as said in the doc? I can try to have a small reproducible example.

I’m using joblib 0.13. (FWIW this code is working on Ubuntu 16.04.5 LTS)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 37
  • Comments: 44 (24 by maintainers)

Commits related to this issue

Most upvoted comments

@robintwhite for now, if this is possible in your case, you can disable memmaping by setting max_nbytes=None in Parallel

Thanks for the details. For now I’m using Parallel with max_nbytes=None.

+1 for a permanent solution. I cannot convert pandas.DataFrame to numpy arrays because I’m using pandas.Series.map() in parallel for fast lookups.

I’m using: pandas 0.24.0 jobllib 0.13.2 numpy 1.15.4 OS: Windows 10

I had the exact same issue when running GridSearchCV for a sklearn-wrapped keras model in parallel. For me the issue was resolved when I used ‘threading’ as joblib’s backend, instead of the default which seems to be ‘loky’:

with joblib.parallel_backend('threading'): 
    grid_result = grid.fit(train_X, train_Y)

Windows 10 Home, sklearn=0.21.2, tensorflow=1.14.0, joblib=0.14.1

Hi guys! I also have this problem, using numpy 1.16.3,scipy 1.2.1,scikit-learn 0.20.3,python 3.7.3, and joblib 0.13.0 (included in scikit-learn). I made sure to have everything in numpy arrays, and also tried to use a parallel instance with max_nbytes=None as input parameter, but no success.

My workaround was to comment out delete_folder(self._workers._temp_folder):

    def terminate(self):
        if self._workers is not None:
            # Terminate does not shutdown the workers as we want to reuse them
            # in latter calls but we free as much memory as we can by deleting
            # the shared memory
            #delete_folder(self._workers._temp_folder)
            self._workers = None

        self.reset_batch_stats()

in \sklearn\externals\joblib\_parallel_backends.py. This is a quick and dirty fix, but at least I get my results this way (the crash happening at the end, when you trained your model for 12h is very frustrating), and I delete the folder in \AppData\Local\Temp\ myself, which didn’t pose any problem until now. Just writing this here if anyone is in the same situation, this is clearly not a good fix.

having the same issue here but the solution from @albertcthomas works for me