Monday, November 15, 2021

[SOLVED] OSError: [Errno 9] Bad file descriptor in pipenv

Issue

I compiled dune in a pipenv virtual environment using Python 3.5.2 on Ubuntu 16.04. It compiled successfully, but when I am running the following script, I get a Bad file descriptor error and do not know why.

from dune.grid import structuredGrid
grid = structuredGrid([0,0],[1,1],[10,10])
grid.plot()

This is the traceback error:

(dune) pcsgs04:[dune] >pipenv run python scripts/testGrid.py 
Traceback (most recent call last):
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/portalocker/portalocker.py", line 137, in lock
    fcntl.flock(file_.fileno(), flags)
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/portalocker/utils.py", line 131, in acquire
    fh = self._get_lock(fh)
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/portalocker/utils.py", line 180, in _get_lock
    portalocker.lock(fh, self.flags)
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/portalocker/portalocker.py", line 141, in lock
    raise exceptions.LockException(exc_value, fh=file_)
portalocker.exceptions.LockException: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "scripts/testGrid.py", line 2, in <module>
    grid = structuredGrid([0,0],[1,1],[10,10])
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/dune/grid/core.py", line 44, in structuredGrid
    return yaspGrid(domain, dimgrid=len(lower))
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/dune/grid/_grids.py", line 40, in yaspGrid
    gridModule = module(includes, typeName, ctor)
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/dune/grid/grid_generator.py", line 199, in module
    module = generator.load(includes, typeName, typeHash, *args, **kwargs)
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/dune/generator/generator.py", line 147, in load
    return self.post(moduleName, source)
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/dune/generator/generator.py", line 105, in post
    module = builder.load(moduleName, source, self.typeName[0])
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/dune/generator/builder.py", line 109, in load
    with Lock(os.path.join(self.dune_py_dir, 'lock-all.lock'), flags=LOCK_SH):
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/portalocker/utils.py", line 197, in __enter__
    return self.acquire()
  File "/home/user/.local/share/virtualenvs/dune-gkp4O1Gp/lib/python3.5/site-packages/portalocker/utils.py", line 157, in acquire
    raise exceptions.LockException(exception)
portalocker.exceptions.LockException: [Errno 9] Bad file descriptor

Can anybody explain me what this issue means, I don't understand exactly what files are locked and throw this exception.


Solution

I guess I had some missing OS rights using pipenv for the virtual environment and ended using miniconda where I didn't have this issue and the script ran without errors.



Answered By - Andreas