Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python error when creating subdirectories #1593

Closed
dhoconno opened this issue Apr 22, 2022 · 9 comments · Fixed by #2057
Closed

Python error when creating subdirectories #1593

dhoconno opened this issue Apr 22, 2022 · 9 comments · Fixed by #2057
Labels
bug Something isn't working

Comments

@dhoconno
Copy link

dhoconno commented Apr 22, 2022

Snakemake version
7.3.8

Describe the bug
This may be related to #1588

I need to run Snakemake within a Docker container. Workflows that used snakemake 5.29.0 work fine.

When I updated to the latest version (7.3.8), there is an error when creating temporary directories.

I'll try to narrow it down further tomorrow but the error appeared between 6.8 and 6.11.1

The issue appears to arise between 6.8.0 and 6.8.1.

I have no name!@xx-2682:/var/lib/condor/execute/slot1/dir_15578$ /opt/conda/envs/snakemake-6.8.0-0/bin/snakemake --cores 1 --snakefile 27185-CHTC.snakefile
KeyError in line 7 of /var/lib/condor/execute/slot1/dir_15578/27185-CHTC.snakefile:
'sample_name'
  File "/var/lib/condor/execute/slot1/dir_15578/27185-CHTC.snakefile", line 7, in <module>
I have no name!@xx-2682:/var/lib/condor/execute/slot1/dir_15578$ /opt/conda/envs/snakemake-6.11.1-0/bin/snakemake --cores 1 --snakefile 27185-CHTC.snakefile
Traceback (most recent call last):
  File "/opt/conda/envs/snakemake-6.11.1-0/lib/python3.10/site-packages/snakemake/__init__.py", line 540, in snakemake
    workflow = Workflow(
  File "/opt/conda/envs/snakemake-6.11.1-0/lib/python3.10/site-packages/snakemake/workflow.py", line 222, in __init__
    self.sourcecache = SourceCache()
  File "/opt/conda/envs/snakemake-6.11.1-0/lib/python3.10/site-packages/snakemake/sourcecache.py", line 275, in __init__
    os.makedirs(self.cache, exist_ok=True)
  File "/opt/conda/envs/snakemake-6.11.1-0/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/opt/conda/envs/snakemake-6.11.1-0/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/opt/conda/envs/snakemake-6.11.1-0/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/opt/conda/envs/snakemake-6.11.1-0/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.cache'

Logs

I have no name!@xx-2673:/var/lib/condor/execute/slot1/dir_4688$ miniconda/envs/snakemake/bin/snakemake -v
7.3.8
I have no name!@xx-2673:/var/lib/condor/execute/slot1/dir_4688$ miniconda/envs/snakemake/bin/snakemake --cores 1 --snakefile 27185-CHTC.snakefile 
Traceback (most recent call last):
  File "/var/lib/condor/execute/slot1/dir_4688/miniconda/envs/snakemake/lib/python3.10/site-packages/snakemake/__init__.py", line 553, in snakemake
    workflow = Workflow(
  File "/var/lib/condor/execute/slot1/dir_4688/miniconda/envs/snakemake/lib/python3.10/site-packages/snakemake/workflow.py", line 232, in __init__
    self.sourcecache = SourceCache()
  File "/var/lib/condor/execute/slot1/dir_4688/miniconda/envs/snakemake/lib/python3.10/site-packages/snakemake/sourcecache.py", line 329, in __init__
    os.makedirs(self.cache, exist_ok=True)
  File "/var/lib/condor/execute/slot1/dir_4688/miniconda/envs/snakemake/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/var/lib/condor/execute/slot1/dir_4688/miniconda/envs/snakemake/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/var/lib/condor/execute/slot1/dir_4688/miniconda/envs/snakemake/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/var/lib/condor/execute/slot1/dir_4688/miniconda/envs/snakemake/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.cache'

Additional context
Running in a Docker container within an HTCondor cluster.

@dhoconno dhoconno added the bug Something isn't working label Apr 22, 2022
@LukaP-BB
Copy link

LukaP-BB commented Jun 1, 2022

I have a very similar issue here with the following traceback :

Traceback (most recent call last):
  File "/dev/envs/shared/pipeline/lib/python3.10/site-packages/snakemake/sourcecache.py", line 330, in __init__
    os.makedirs(self.cache, exist_ok=True)
  File "/dev/envs/shared/pipeline/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/dev/envs/shared/pipeline/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/dev/envs/shared/pipeline/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  [Previous line repeated 2 more times]
  File "/dev/envs/shared/pipeline/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home'

I added some error handling to the line in sourcecache.py, to see which folder was trying to be created exactly, and this is the one that fails :

  File "/labos/UGM/dev/envs/shared/pipeline/lib/python3.10/site-packages/snakemake/sourcecache.py", line 332, in __init__
    raise Exception(f"{os.environ.get('USER')} could not create folder tree : '{Path(self.cache).resolve().absolute()}'")
Exception: user could not create folder tree : '/home/user/.cache/snakemake/snakemake/source-cache'

This folder actually exists, so this is really mind-boggling and I'm running out of ideas to debug this issue.
Is there a way to specify where the snakemake cache will be written ? Because the space in /home/user is limited

@james-s-willis
Copy link

I ran into the same problem today running snakemake v7.3.8 from within a container:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/snakemake/__init__.py", line 553, in snakemake
    workflow = Workflow(
  File "/usr/local/lib/python3.8/site-packages/snakemake/workflow.py", line 232, in __init__
    self.sourcecache = SourceCache()
  File "/usr/local/lib/python3.8/site-packages/snakemake/sourcecache.py", line 333, in __init__
    self.runtime_cache = tempfile.TemporaryDirectory(
  File "/usr/local/lib/python3.8/tempfile.py", line 780, in __init__
    self.name = mkdtemp(suffix, prefix, dir)
  File "/usr/local/lib/python3.8/tempfile.py", line 358, in mkdtemp
    _os.mkdir(file, 0o700)
OSError: [Errno 30] Read-only file system: '/home/.cache/snakemake/snakemake/source-cache/runtime-cache/tmpw2ugmobm'

I found the environment variable, SNAKEMAKE_OUTPUT_CACHE from: https://snakemake.readthedocs.io/en/stable/executing/caching.html?highlight=SNAKEMAKE_OUTPUT_CACHE#between-workflow-caching
as a possible solution. However, it is not used in the code to set the cache path. snakemake actually uses appdirs.user_cache_dir to set the path:

os.path.join(get_appdirs().user_cache_dir, "snakemake/source-cache")

I managed to fix this issue by setting:

export XDG_CACHE_HOME=/scratch

which is used by https://github.com/ActiveState/appdirs to set the cache path.

I think the documentation for SNAKEMAKE_OUTPUT_CACHE needs to be updated

@LukaP-BB
Copy link

LukaP-BB commented Jun 1, 2022

I'm pretty sure the SNAKEMAKE_OUTPUT_CACHE has nothing to do with the runtime cache where the error is raised, as it is used to cache common results from rules between workflows. @james-s-willis

@LukaP-BB
Copy link

LukaP-BB commented Jun 2, 2022

I managed to fix the issue with something that looks completely unrelated.
Working on a cluster with slurm, my drmaa string included --mem-per-cpu={cluster.mem}
Switching this to --mem={cluster.mem} and adapting the cluster mem accordingly fixed it.
There was an issue with the process going out of memory and giving enough memory to the batch job fixed it.
I still don't see how this would interfere with the SourceCache() initialization 🤔

@james-s-willis
Copy link

@LukaP-BB thanks for the tip, I didn't realise that SNAKEMAKE_OUTPUT_CACHE was something completely different.

Regarding your fix, I can see how setting --mem-per-cpu={cluster.mem} would cause it to OOM, but I agree I don't see how this would have anything to do with SourceCache initialisation.

@moxgreen
Copy link

I had the same issue and I solved by modifying the container. I added this rule to dockerfile:

RUN mkdir /.cache; chmod a+rwX /.cache

@dhoconno
Copy link
Author

Thanks to @moxgreen -- this solution worked great!

@peter-yufan-zeng
Copy link

I had the same problem running snakemake 7.3.8 (installed via pip) on my slurm cluster. On my cluster, HOME directory is not modifiable on the compute nodes. I solved the problem by manually setting the self.cache in sourcecache.py to my scratch directory.

snakemake/snakemake/sourcecache.py

johanneskoester added a commit that referenced this issue Jan 16, 2023
resolves #2031
resolves #1593 

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).
@AlcaArctica
Copy link

AlcaArctica commented Oct 2, 2023

Wow, thank you @peter-yufan-zeng and @moxgreen!
I just spent the whole morning on a very similar problem, but I didnt find your issue, because I am getting a different error.
Background is, I am trying to run snakemake with --profile on our cluster using slurm (snakemake v7.32.4). I obtained the slurm profile via cookiecutter from https://github.com/Snakemake-Profiles/slurm without modifications. Before snakemake would run just fine. But when trying to use the --profile flag, I would get the following very strange error:

Traceback (most recent call last):
  File "/lustre/projects/dazzler/uelze/conda_envs/snakemake/lib/python3.11/site-packages/snakemake/__init__.py", line 610, in snakemake
    workflow = Workflow(
               ^^^^^^^^^
  File "/lustre/projects/dazzler/uelze/conda_envs/snakemake/lib/python3.11/site-packages/snakemake/workflow.py", line 235, in __init__
    self._sourcecache = SourceCache()
                        ^^^^^^^^^^^^^
  File "/lustre/projects/dazzler/uelze/conda_envs/snakemake/lib/python3.11/site-packages/snakemake/sourcecache.py", line 353, in __init__
    os.makedirs(self.cache, exist_ok=True)
  File "<frozen os>", line 215, in makedirs
  File "<frozen os>", line 215, in makedirs
  File "<frozen os>", line 215, in makedirs
  [Previous line repeated 1 more time]
  File "<frozen os>", line 225, in makedirs
OSError: [Errno 107] Transport endpoint is not connected: '/home/uelze'

I tried de-installing and re-installing and updating snakemake, but kept getting the same error. Finally I found your post and I manually set the self.cache in sourcecache.py to my scratch directory and giving all users permissions on that directory with chmod a+rwX.
This fixed the error. I am not sure what caused it, but maybe similar to @peter-yufan-zeng our slurm cluster was unable to access my home? Anyway, our storage quota in our home is quite restricted, so its good to re-direct anything possible to a different location anyway. So thanks so much for having documented this before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants