Re: Writing to function arguments during execution
- From: "John O'Hagan" <research@xxxxxxxxxxxxxx>
- Date: Wed, 14 Oct 2009 13:29:41 +1100
On Mon, 12 Oct 2009, Rhodri James wrote:
On Sun, 11 Oct 2009 14:18:25 +0100, John O'Hagan <research@xxxxxxxxxxxxxx>
wrote:
Now I can change the output of the "work" function while it's running via
raw_input(). However it's very crude, not least because the terminal
echo of
the new options is interspersed with the output of the program.
In future I hope to be able to have several instances of the "work"
function
running as threads simultaneously, and to separately control the
arguments to
each.
I think the general problem is how to send output from a thread to a
different
place from that of its parent thread, but I'm not sure.
Is there a standard way to do this kind of thing? In particular, I'm
after a
solution whereby I can enter new arguments in one terminal window and
observe
the program's output in another.
The standard way (if you don't want to write a GUI for the whole thing)
is to have separate programs communicating with sockets. Start your
music program in one terminal and the control program in the other,
and have a thread listening to the socket rather than using raw_input().
Thanks, sockets are the way to go for this and surprisingly easy to use once
you get your head around them. I tried Rhodri's suggested approach but for now
I used the original terminal for both starting the program and entering new
options (still via raw_input) and a new terminal listening on a socket
connection to display the results.
A secondary question: right now I'm starting the "listening" terminal by
executing a script ('display.py') as a subprocess:
port = 50007
here = os.path.abspath('')
terminal = os.environ['TERM']
subprocess.Popen([terminal, '-e', here + '/display.py', str(port)])
but to me it feels kind of clunky to have a separate script just for this; is
there a nicer way to launch another terminal, say by passing a locally defined
function to it?
Regards,
John
.
- Prev by Date: Re: What is Islam?-1
- Next by Date: Question regarding multiprocessing and error: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed
- Previous by thread: Re: Writing to function arguments during execution
- Next by thread: Re: Writing to function arguments during execution
- Index(es):
Relevant Pages
|