Skip to content

Parallel iterators and notebook mode results in a deadlock #25

@istoleyurballs

Description

@istoleyurballs

Hi,
I think I found a bug when using the notebook and rayon features at the same time.

This snippet seems to cause a deadlock.

#[pyfunction]
fn my_function(something: &[u8]) {
  kdam::set_notebook(true);
  kdam::par_tqdm!(something.par_iter()).something();
}

When calling this function inside a jupyter notebook, it just hang indefinitely.

Workarounds

Turning off notebook mode works but defeats the purpose.

Wrapping the iteration inside a py.allow_threads(|| ...) seems to also resolve the issue.

However in this sort of notebook workflow you often iterate over things that come from python, so not holding the GIL during the entire function is often wrong and could result in unexpected memory races.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions