AnswerDotAI / AnswerDotAI/nbdev

nbdev_prepare and nbdev_test hang if I use the parallel library with loky as the backend

Offen
#1,365 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
Jupyter Notebook
Sterne
5.3k
Forks
513
Ø Merge
2 T. 30 Min.
Gemergte PRs (30 T.)
8

Beschreibung

(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).

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, das minimale Beispiel mit nbdev_test und nbdev_prepare zu reproduzieren, und untersuche dann nbdev/test.py um die Zeilen 90–91, wo die parallele Ausführung erwähnt wird. Vergleiche die Fälle loky, threading und --n_workers=0 in der gemeldeten Umgebung. Erledigt ist die Aufgabe, wenn das reproduzierbare Notebook ohne Hängenbleiben abgeschlossen wird und dabei die normale parallele Ausführung erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter, python
Bereich
testing-qa, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.