Skip to content

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

@Taytay

Description

@Taytay

(First, thanks for nbdev. This project is great!)

Minimally reproducible example

This code in my notebook causes nbdev_test to hang indefinitely:

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions