<div dir="ltr">To who cares, I found out what my problem was.<br><br>Testing interactivity with Tk in a normal Python console gave proper<br>results, just like IPython. Also running "python -i" gives the <br>interactive behaviour I wanted. But running "python -i" from a subprocess<br>
did not. I was startled, because it worked out of the box with Python!<br><br>I read somewhere that Tkinter does not need a mainloop, which should be <br>true in order to have the interactive behaviour in python without a second <br>
thread. Well, tk does indeed not need a mainloop, but you DO need to<br>create a tk app and call update() on it from time to time. (Which makes<br>sense now that I know it :) )<br><br>After examing code from IPython, I saw that it runs code to start a Tk app,<br>
and performs tk.update().<br><br>So I guess this means that the standard python shell creates such a <br>"hidden tk app", but NOT when run from a subprocess.<br><br>I have now solved my problem, and interactivity works! <br>
<br>Almar<br><br><br><br><br><div class="gmail_quote">2008/9/20 Almar Klein <span dir="ltr"><<a href="mailto:almar.klein@gmail.com">almar.klein@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">I think my question was not very clear. I narrowed the problem down to<br>a reconstructable small example, consisting of a python script (a very <br>simple interpreter) and three lines to execute in it:<br>
<br>
========== start simple interpreter file ======<br>import os<br>import sys<br>import time<br><br>def run():    <br>    while True:<br>        <br>        # read a line of text, the thread is stuck here untill a \n is<br>
        # fed to the stream.        <br>
        time.sleep(0.1)<br>        line = ""     <br>        try:                    <br>            line = sys.stdin.readline()<br>        except Exception, why:<br>            sys.stdout.wite(why.message+"\n")<br>

                <br>        if line:<br>            try:                <br>                code = compile(line,"<none>","exec")<br>                exec(code)<br>            except Exception, why:                <br>

                sys.stderr.write(why.message)<br>            sys.stderr.write(">>> ")<br>                <br>if __name__ == "__main__":      <br>    run()<br><br>========== end of file ==============<br>

<br>Now I run this file (by double clicking it) and I get a prompt. The three lines I type in are:<br>import matplotlib.pylab as pl<br>pl.ion() #interactive mode on<br>pl.plot([1,2,3],[4,6,5])<br><br>This produces a tk window, but it's unresponsive. The process does have 5 threads, so<br>

matplotlib managed to create the threads, but it seems as if they're blocked.<br><br>When I run the three lines of code in a normal python shell, I get the proper results: <br>a responsive figure (I can zoom and pan) and my shell is still responsive too.<br>

<br>I am in the dark why this does not work. Any thoughts anyone? I've been busy all day<br>trying to get this right, with hardly any progress... :(<br><br>Almar<br><br>PS: I run windows xp, my matplotlibrc file has the backend: TkAgg, interactive: True<br>

<br><br><div class="gmail_quote">2008/9/18 Almar Klein <span dir="ltr"><<a href="mailto:almar.klein@gmail.com" target="_blank">almar.klein@gmail.com</a>></span><div><div></div><div class="Wj3C7c"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


<div dir="ltr">Hi,<br><br>In wxpython, I made an interactive shell, which creates a remote python subprocess<br>to do the interpreting. Communication is done via a pipe. The idea is that the python<br>session is an actual process separate from the GUI, which has some advantages, <br>



like I can have multiple such shells in my application, and I can kill them without <br>worrying that my wx app will crash.<br><br>To do this I use the wx.Process class, which allows asynchronous communication with<br>the remote process.<br>




<br>This all works really, I will also launch wxpython apps. So I was quite happy, untill I tried <br>doing some plotting with matplotlib (in TkAgg backend). The problem is that the process <br>becomes unresponsive when I plot something (No prompt is written to the stdout/stderr). <br>



(more details below)<br><br>I don't know much about creating subprocess and how they are different from a normal <br>process. So can anyone offer some help as to what the problem might be?<br><br>Thanks in advance,<br>



Almar<br><br>To get to the details:<br>- When I start a process with command "python -u -i"<br>  -- When interactive mode is off, the whole process becomes unresponsive when doing <br>     pylab.show()<br>  -- When interactive mode in on, on doing pylab.plot(), a figure appears, which I can <br>




    zoom etc., but the process is now stuck, also after closing the figure<br><br>- When I start a process with command <br>  "python -u -c 'import code;code.interact(readfunc=raw_input)'"  (This is how Pype does it).<br>




  -- When interactive mode is off, the figures show when doing pylab.show() and the process<br>     behaves as normal after closing the figure(s).     <br>  -- When interactive mode in on, on doing pylab.plot(), a figure appears, but most of the time<br>




     it is not drawn and emmediately unresponsive, just like the process itself.<br><br>I have also tried an asynchronous Popen recipe by Joshiah Carlson I found on <br>activestate. And I made my own process class using win32process.CreateProcess. <br>



Both alternatives to wx.Process resulted in the same sympoms.<br><br>Oh, and I run windows.<br><br></div>
</blockquote></div></div></div><br></div>
</blockquote></div><br></div>