question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stopping a submitted function in Jupyter Notebook results in <FutureState: error> and a needed restart

See original GitHub issue

The client enters a <FutureState: error> state when a job is submitted to the client and the kernel is stopped.

This is a problem because once in that state, no other jobs can be completed (client.gather(result) blocks but does not complete for any submitted future jobs).

The only way to progress is to restart the Jupyter notebook kernel.

Instructions to reproduce, paste this code into a Jupyter Notebook cell:

import time
from dask.distributed import Client

client = Client()

def add(a,b):
    time.sleep(60)
    return a+b

def square(a):
    return a**2

Then run the below code and stop the kernel prior to the function completing (<60s).

result = client.submit(add, 1, 4)
client.gather(result)

Checking the client futures, we can see an error FutureState:

>>> client.futures
{'add-962bd7f68184e275518de72ad6b32ed9': <FutureState: error>}

Attempting to execute other functions thereafter results in the client.gather function blocking any further execution:

result2 = client.submit(square, 5)
client.gather(result2)

The only way to revert back to the expected behaviour is to restart the Jupyter notebook kernel (which is not ideal if a lot of data has been loaded from disk)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
mrocklincommented, Sep 5, 2017

By the way @gregsifr thank you for producing such a clean example of this issue

0reactions
GenevieveBuckleycommented, Oct 15, 2021

It looks like the patch to CPython has been applied and released, so I’ll close this issue. Thanks @gregsifr

Read more comments on GitHub >

github_iconTop Results From Across the Web

jupyter: how to stop execution on errors? - Stack Overflow
To do what you want, just raise an exception of the correct type. If it propagate to the eval loop, IPython will stop...
Read more >
How to reset a Jupyter notebook(to resolve kernel crashes)
Solution. You need to clear the Jupyter notebook of all its code cell results. To do this, do the following. Open a new...
Read more >
API — Dask.distributed 2022.12.1 documentation
Submit a function application to the scheduler. Client.subscribe_topic (topic, handler). Subscribe to a topic and execute a handler for every received event.
Read more >
B. Jupyter Notebook Tutorials
In this tutorial, we will be loading in data that has been produced in Hadjimichael et al. (2020). Before we start our analysis,...
Read more >
Futures — Python 3.11.1 documentation
Future objects are used to bridge low-level callback-based code with high-level async/await code. Future Functions¶. asyncio.isfuture(obj) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found