From: Fernando P. <Fer...@co...> - 2005-01-30 18:43:40
|
Steve Chaplin wrote: > To run a background process as a thread you would need to redirect its > stdout somewhere (StringIO for example). The problem with using threads > for this is that they share the stdout with the main thread, so if you > redirect the background threads stdout you will redirect the python > interpreters stdout too! > You could run a background process as an actual process and not a thread > (and Python 2.4 has a new subprocess module which unifies the previous > solutions of os.system, os.spawn*, os.popen*, popen2.*, commands.*). It > lets you redirect stdout, but is used for running executables, not > calling python functions. > > It has me stumped too, how can you call a python function and redirect > its stdout independent of the python interpreters stdout? Not as far as I know. That's why I think the only solution for the whole 'backgrounding' problem with stdout is to put everything into a gui window (a la mathematica notebooks). I've been thinking about it, and the proper way to write it is probably with _two_ python processes. One would be the gui environment, and the other would be just a 'kernel' executing commands. The stdout of the kernel would then be connected to an object capable of putting the results of each command next to the input cell which generated them. I bet that's pretty much how Mathematica is organized, simply because it looks like the only reasonable way to deal with the issue. Cheers, f |