AnswerDotAI / AnswerDotAI/nbdev

nbdev_test fails when notebook imports polars package due to `set_start_method` conflict

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

Beschreibung

# Failure and repro

Trivial notebook/nbdev repo with `import polars as pl` fails ([repro CI run](https://github.com/daniel-vainsencher/nbdev-polars-mp-bug-repro/actions/runs/3329229804/jobs/5506182947)) with error message:
```
ImportError: Polars only works with python multiprocessing method set to: `mp.set_start_method("spawn")` or `mp.set_start_method("forkserver")`before importing polars. See: https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
```
and the stack confirms (lines 324-5) the method is set to `fork`.

This reproduces locally (Linux) under nbdev_test, but not when run in a jupyter-notebook, thus I am assuming the difference is nbdev_test or a dep.

# Context

[Polars explanation](https://pola-rs.github.io/polars-book/user-guide/howcani/multiprocessing.html) of their assertion seems to suggest `fork` is not a uniformly appropriate choice.

I have not found nbdev_test UI to easily override the method (which would be a reasonable workaround).

# My investigation so far

Candidate deciders of the method/callers of `set_start_method` include [nbdev_test](https://github.com/fastai/nbdev/blob/656b7bc26c8760f839a6106250f071e8e096397c/nbdev/test.py#L87) (which seems to implicitly allow 'fork'), or [fastcore](https://github.com/fastai/fastcore/blob/91cdf9930914d0043b958cbdc040ab39db29a762/fastcore/parallel.py#L19) (but CI is not on darwin) and [shell](https://github.com/fastai/execnb/blob/master/nbs/02_shell.ipynb) (but again, not on darwin).

I did not find justification for the different rules being applied to set the start method, and am not familiar enough with multiprocessing to propose a wise patch. But, as a relative newcomer to nbdev who is loving both it and polars, I thank everyone working on both and hope we can fix the conflict.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit nbdev/test.py in Zeile 87 und dem verknüpften repro-CI-Lauf, und verfolge dann die Einrichtung von multiprocessing durch fastcore/parallel.py in Zeile 19 und das execnb-Shell-Notebook. Bestätige, welche Komponente fork auswählt, und teste einen kompatiblen nbdev_test-Pfad mit dem polars-Notebook. Als erledigt gilt die Aufgabe, wenn das repro unter nbdev_test besteht, ohne das bestehende multiprocessing-Verhalten zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
jupyter-notebook, python
Bereich
backend, testing-qa
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

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