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

Asynchrous issue when using clear_display and print x,y,z #1539

Closed
piti118 opened this issue Mar 31, 2012 · 1 comment · Fixed by #1541
Closed

Asynchrous issue when using clear_display and print x,y,z #1539

piti118 opened this issue Mar 31, 2012 · 1 comment · Fixed by #1541

Comments

@piti118
Copy link
Contributor

piti118 commented Mar 31, 2012

A minor issue

from IPython.core.display import clear_output
import time
class xxx:
    def __init__(self,color):
        self.color = color
    def _repr_html_(self):
        return '<span style="color:%s">woot</span>'%self.color
for i in range(10):
    x = xxx(['red','green','blue'][(i%3)])
    print 1,2,3
    clear_output(stdout=False, stderr=False, other=True)
    display(x)
    time.sleep(2)

This produce a funny looking output like

1 2 3
1
 2 3
1
.
.
.

Which the raw html is

<pre> 1 2 3
1</pre>

then

<pre>2 3
1
</pre>

While

print 1,
print 2,
print 3,

works just fine. It also works fine if I remove sleep function.

@minrk
Copy link
Member

minrk commented Mar 31, 2012

The issue is (as usual with print weirdnesses) an issue of display_pub and print talking on the same channel, but print statements not writing to the stream until stdout.flush() is called, which is triggered implicitly and asynchronously by some arcane magic.

Solution: display_pub methods should imply sys.stdout/err.flush() to preserve ordering.

See PR #1541 for such a fix.

@minrk minrk closed this as completed in 75fa2b8 Apr 4, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
display_pub flushes stdout/err

This helps preserve ordering of print statements and display_pub output.

closes ipython#1539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants