Threading an Interactive Console in a Running Process
<p>I would like to start an interactive console during a running python process from the command line, but not interrupt the python process.</p>

<p>I'm using <a href="http://stackoverflow.com/a/4693529/638323">http://stackoverflow.com/a/4693529/638323</a> as a pattern, but I'm not sure how to get the threading right.  Right now, whenever I signal my app, everything halts, except the console thread.  Am I heading in the right direction, or should I try something more like <a href="http://stackoverflow.com/a/4693529/638323">http://stackoverflow.com/a/4693529/638323</a> to interact with a running python process without interrupting other threads</p>

<p>Here's a small example</p>

<pre><code>class MyClass:
    def __init__(self):
        self.run_count = 0
    def run(self):
        while(True):
            self.run_count+=1
            #I added a print statement just to see where it 
            #picked up and left off in the terminal
            if(self.run_count%10000 == 0):
                print(self.run_count)

if __name__ == "__main__":
    signal.signal(
        vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR2"),
        lambda sig, frame: threading.Thread(target=code.interact(local=dict(globals(),**locals()))).start() 
    )
    mc = MyClass()
    threading.Thread(target=mc.run()).start()
</code></pre>

<p>What I expect to happen is the main thread spawns a thread that iterates mc.run_count and when a ctrl-break signal is received, spawns a new thread with a interactive prompt.  Since I don't think I see this, I suspect I misunderstand signal or threading (or both)</p>
