InteractiveConsole executed in another thread.

G

Germán Diago

Hello. I have an application written in python (it's a wrapper for a
c++ application).

The application has : a window (an SDL window), and a GUI, which has
the window embedded inside.

I would like to use InteractiveConsole to send commands to the SDL window.

I have an API that allows me to do this, but when trying to put
InteractiveConsole in another thread,
my program gets blocked at that point.

I mean:

class FileCacher:
"Cache the stdout text so we can analyze it before returning it"
def __init__(self): self.reset()

def reset(self): self.out = []

def write(self,line): self.out.append(line)

def flush(self):
output = '\n'.join(self.out)
self.reset()
return output


class Shell(InteractiveConsole):
"Wrapper around Python that can filter input/output to the shell"
def __init__(self):
self.stdout = sys.stdout
self.cache = FileCacher()
InteractiveConsole.__init__(self)
return

def get_output(self): sys.stdout = self.cache
def return_output(self): sys.stdout = self.stdout

def push(self,line):
self.get_output()
# you can filter input here by doing something like
# line = filter(line)
InteractiveConsole.push(self,line)
self.return_output()
output = self.cache.flush()
# you can filter the output here by doing something like
# output = filter(output)
print output # or do something else with it
return

class ShellThread(threading.Thread):
def run(self):
sh = Shell()
sh.interact()

The program blocks at interact as if there were no more threads, and
there are 2 python
threads in the program (and one native thread, which releases the GIL
correctly from c++).

Any hints why the Console thread blocks the other one? Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top