Skip to content

Use filelock while starting a new kernel. #327

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hodgestar
Copy link

@hodgestar hodgestar commented Apr 16, 2025

I use nbmake and pytest-xdist to run many notebook tests in parallel on a CI machine with 64 cores. This frequency triggers the long standing jupyter_client bug jupyter/jupyter_client#487 whose proposed solution is detailed in a Jupyter enhancement proposal accepted in 2023 -- jupyter/enhancement-proposals#66.

When launch many local kernels, the obvious solution seems to be to hold a file lock during kernel start up. This PR implements that solution using https://github.com/tox-dev/filelock.

I've put up this PR without any tests yet as a request for feedback.

Questions:

  • Should the filelock dependency be made optional? [Tentative answer: Probably]
  • Should there be a filelock by default? [Tentative answer: Probably not -- the lock file path is likely not known at this level]
  • What else would be needed to get this merged?

Many thanks to wandb/wandb#8835 for the idea behind the PR.

github-merge-queue bot pushed a commit to Qiskit/documentation that referenced this pull request May 16, 2025
This PR uses a lock to try and avoid this error when running in a GitHub
action:

```
zmq.error.ZMQError: Address already in use (addr='tcp://127.0.0.1:45769')
```

This is a bit of a shot in the dark because I can't reproduce it
locally.

This is related to #2387, but is not necessarily a full fix as I believe
there is more than one thing going on there.

***

Inspired by jupyter/nbclient#327
@mschilli87
Copy link

I am hitting this using Snakemake's notebook: feature when running on several cores at once. If there is anything I can contribute to finally make Jupyter notebooks parallel-safe, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants