Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash cells show no intermediate output #2023

Closed
MarkDunne opened this issue Jan 5, 2017 · 8 comments
Closed

Bash cells show no intermediate output #2023

MarkDunne opened this issue Jan 5, 2017 · 8 comments

Comments

@MarkDunne
Copy link

MarkDunne commented Jan 5, 2017

The %%bash cell does not show any output until everything is finished running.

For example

%%bash
echo "Hello 1"
sleep 5
echo "Hello 2"

Will not output "Hello 1" until the whole cell is done, 5 seconds later.

My use case for this is that in my pipeline, I have some rather long process calls that ideally I would like to run via my notebook. However, not being able to inspect the output while it's running makes things difficult. Clearly for python cells this isn't a problem, can we solve it for bash cells?

@MarkDunne MarkDunne changed the title %%bash cell shows no intermediate output Bash cells show no intermediate output Jan 5, 2017
@kscd
Copy link

kscd commented Jan 15, 2017

To me it seems that this is a bug in Ipython rather than in the notebook, since I was able to reproduce the same behavior in a simple ipython shell with the command

In [1]: %%bash
   ...: echo '1'
   ...: sleep 3
   ...: echo '2'
   ...: 

whereas

In [2]: import time
In [3]: print('1') ; time.sleep(3) ; print('2')

prints first the 1 and three seconds later the 2.

@gnestor gnestor added this to the Not Notebook milestone Jan 26, 2017
@gnestor gnestor added the bug label Jan 26, 2017
@tijlk
Copy link

tijlk commented Sep 8, 2017

I'm having the same problem. Would be nice to have this fixed. Otherwise I'm forced to run the bash scripts outside the notebook in order to have any idea of what's going on.

@mpacer
Copy link
Member

mpacer commented Sep 8, 2017

@minrk is there anything we can do in terms of treating different lines of a bash cell (that aren't continued with\) as different messages so they can each send back their results piece by piece?

@minrk
Copy link
Member

minrk commented Sep 8, 2017

It doesn't need to be executed as a separate cell, we just need to make sure we flush and republish the output we receive from the subprocess more frequently. I don't recall how exactly we are doing that right now.

@ghost
Copy link

ghost commented Feb 1, 2018

Would be great fix this for long running processes. Maybe something similar to what running bash scripts like !foo.sh does? The ! shortcut displays intermediate output. Thanks!

@ghost
Copy link

ghost commented Jun 13, 2018

The solution seems to be not using the default python kernel but using the bash kernel from https://github.com/takluyver/bash_kernel

python -m bash_kernel.install

Restart your jupyter notebook, create a bash session, and you'll get immediate stdout/stderr display.

@boshokor
Copy link

this is rather a hack but it is possible to do it using subprocess module. following this question and assuming test.sh have the example given by @kscd it is possible to do it like this

import subprocess, time, os, sys
cmd = ["./test.sh"]

p = subprocess.Popen(cmd,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)

for line in iter(p.stdout.readline, b''):
    print(">>> " + line.decode().rstrip())

rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue Mar 31, 2019
rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue Mar 31, 2019
rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue Apr 4, 2019
rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue Apr 5, 2019
rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue May 28, 2019
rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue Jun 6, 2019
rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue Jun 7, 2019
rhaas80 added a commit to rhaas80/jupyter-et that referenced this issue Sep 11, 2019
rhaas80 added a commit to nds-org/jupyter-et that referenced this issue Sep 12, 2019
@benlau
Copy link

benlau commented Jan 2, 2022

I have made a cell magic called livebash to provide an alternative solution (plus extra features) for this problem:

https://github.com/benlau/ipylivebash

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants