OSError: [Errno 9] Bad file descriptor in pipenv

OSError: [Errno 9] Bad file descriptor in pipenv

我在 Ubuntu 16.04 上使用 Python 3.5.2 在 pipenv 虚拟环境中编译了 dune。它编译成功,但是当我运行以下脚本时,我得到一个Bad file descriptor错误,不知道为什么。

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

这是回溯错误:

(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

任何人都可以向我解释这个问题是什么意思,我不明白究竟是什么文件被锁定并抛出这个异常。

我想我在虚拟环境中使用 pipenv 时缺少一些 OS 权限,最后使用 miniconda 时我没有遇到这个问题,脚本 运行 没有错误。