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.

Cells get executed using different threads

See original GitHub issue

Cells get executed using different threads

This is a design question and a possible bug.

As you execute different cells in a C# or F# notebook, a different thread gets used for each interaction. The question is really whether we want to guarantee that the same thread gets used each time you execute a new cell. Since cell execution is inherently linear it feels we should likely guarantee this.

For example, repeated re-execution of

System.Console.WriteLine("{0}", System.Threading.Thread.CurrentThread.ManagedThreadId);

gives 10, 11 etc.

This came up when using TensorFlow.NET, which had some thread local storage that was not getting re-initialized correctly as operations were performed from different threads. But the question is more general too - is is something we want to guarantee or not, and we should document it either way.

Please complete the following:

  • OS
    • Any
  • Browser
    • Any

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
lostmsucommented, Apr 20, 2021

Either I am misunderstanding something, or library code should not be affected. All new tasks started from interactive should use standard SynchronizationContext and can execute on any worker thread. Single thread should only affect the top-level call.

1reaction
dsymecommented, Apr 14, 2021

So I’m not suggesting changing how TensorFlow or other libraries work, but rather adding kernel extensions to their NuGet packages that customize the behavior of .NET Interactive’s threading model in the presence of those libraries.

I don’t think this is realistic. The TensorFlow threading model is not particularly strange and it’s not possible to go round patching up the package ecosystem to include dependencies on .NET Interactive

We should just make it possible to configure .NET Interactive to respect a single-threaded execution model without any changes to package ecosystems. A magic command would be enough.

@lostmsu We should work together to get a proposed fix for this I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Run cells in different threads · Issue #1155 · jupyter/notebook
Hi,. Sometimes I run long code in some cell, and still want to be able to run small snippets (independant) in another cell....
Read more >
Multithreaded recalculation in Excel
Excel tries to identify parts of the calculation chain that can be recalculated concurrently on different threads. The following very simple ...
Read more >
sql table cell modified by multiple threads at the same time
If the problem is that several threads read and set the value at almost the same time, and reads and writes don't arrive...
Read more >
What is multithreading?
With multithreading, while the computer system's processor executes one instruction at a time, different threads from multiple programs are executed so fast it ......
Read more >
Reading Cell Values in Multiple Threads Simultaneously
Needing to read cell values in multiple threads simultaneously is a common requirement. This article explains how to use Aspose.Cells for this purpose....
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