<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Mar 16, 2014 at 6:30 PM, Doug Blank <span dir="ltr"><<a href="mailto:doug.blank@gmail.com" target="_blank">doug.blank@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If you run the following cell:<br>
<br>
import threading<br>
import time<br>
class ThreadClass(threading.Thread):<br>
    def run(self):<br>
        x = 1<br>
        while True:<br>
            print(x)<br>
            x += 1<br>
            time.sleep(1)<br>
t = ThreadClass()<br>
t.start()<br>
t.join()<br>
<br>
Then you will see the data for as long as you don't interrupt the<br>
cell. If you comment out the t.join(), then you won't see any output<br>
(or maybe just the first printed).<br>
<br>
In the next cell, if you do something such as, say:<br>
<br>
while True:<br>
    pass<br>
<br>
and then interrupt the kernel, you'll see some more of the printouts.<br>
<br>
It appears that when the execution_reply is received, the notebook<br>
doesn't take output messages anymore. Is this all by design? Is there<br>
a manner to make sure background-running output can still make its way<br>
to the notebook?<br></blockquote><div><br></div><div>zmq sockets are not threadsafe. To protect against segfaults, background threads are not allowed to write directly to the IOPub socket. What they do instead is write to a buffer, which the main thread checks periodically. That's why async output from a thread doesn't show up until there is some interaction in the main thread.</div>

<div><br></div><div>It would be easy enough to hook up that checking / flushing to the main eventloop, in which case it would still be threadsafe, but still allow publication while the kernel is idle. But that's now how it works right now.</div>

<div><br></div><div>-MinRK</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-Doug<br>
_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
</blockquote></div><br></div></div>