AnswerDotAI / AnswerDotAI/nbdev
nbdev_prepare and nbdev_test hang if I use the parallel library with loky as the backend
- Lingua principale
- Jupyter Notebook
- Stelle
- 5.3k
- Fork
- 513
- Merge medio
- 2g 30m
- PR unite (30g)
- 8
Descrizione
(First, thanks for nbdev. This project is great!)
# Minimally reproducible example
This code in my notebook causes `nbdev_test` to hang indefinitely:
```python
with parallel_backend("loky"):
def g(y):
return y + 1
Parallel(n_jobs=2)(delayed(g)(y) for y in [1, 2, 3, 4])
```
But specifying "threading" as the backend works:
```python
with parallel_backend("threading"):
def g(y):
return y + 1
Parallel(n_jobs=2)(delayed(g)(y) for y in [1, 2, 3, 4])
```
The other thing that allows this to work is passing --n_workers=0 to nbdev_test.
Note that "loky" is the default backend, so not specifying a backend when using parallel also fails.
This is a Mac M1
I'm on Python 3.9.18
nbdev 2.3.12
fastcore 1.5.29
Tried upgrading loky and joblib to 3.4.1 and 1.3.2 just to make sure that wasn't the issue. (It wasn't)
It's clearly related to the use of parallel in nbdev_test, but that's as far as I got:
https://github.com/fastai/nbdev/blob/4af4d479c78880f4a18af4254b119f8af8b3a8a4/nbdev/test.py#L90-L91C6
(I'm posting this here in case others are using Parallel and are stymied when nbdev_test (or nbdev_prepare) stops working.
If said people stumble across this, note that setting the parallel backend to threading makes your code _MUCH_ slower due to the Python GIL).
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo l’esempio minimo con nbdev_test e nbdev_prepare, quindi esamina nbdev/test.py intorno alle righe 90-91, dove viene menzionata l’esecuzione parallela. Confronta i casi loky, threading e --n_workers=0 nell’ambiente indicato. Il lavoro è completato quando il notebook riproducibile termina senza bloccarsi, preservando al contempo la normale esecuzione parallela.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- jupyter, python
- Ambito
- testing-qa, tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100