STDIN prompts rendering is nondeterministic with respect to stream outputs
- Dominant language
- Jupyter Notebook
- Stars
- 13.3k
- Forks
- 5.8k
- Avg merge
- 6d 11h
- Merged PRs (30d)
- 7
Description
I believe the Jupyter FE is receiving STDIN and stream messages in a nondeterministic order.
Here's a small repro:
```python
import getpass, sys
print (2)
sys.stdout.flush()
_ = getpass.getpass()
```
I would expect this to render 2 before the getpass prompt in all executions. Yet, if I execute this a few times, I occasionally see the reverse order. (Perhaps 1-2 instances in 10 executions.)
Example screenshot:

My conjecture is that what is happening is that STDIN channel messages and IOPUB messages are not deterministically ordered for a given cell execution.
Contributor guide
Research direction
Start by running the provided Python repro repeatedly and observing the Jupyter frontend's rendering of STDIN and IOPUB stream messages. Investigate how those messages are ordered for one cell execution; done means the printed 2 consistently appears before the getpass prompt.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- backend, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100