Search code examples
pythonshellterminal

Outputting text to multiple terminals in Python


(I am using Python and ArchLinux)

I am writing a simple AI in Python as a school project. Because it is a school project, and I would like to visibly demonstrate what it is doing, my intention is to have a different terminal window displaying printed output from each subprocess- one terminal showing how sentences are being parsed, one showing what pyDatalog is doing, one for the actual input-output chat, etc, possibly on two monitors.

From what I know, which is not much, a couple of feasible ways to go about this are threading each subprocess and figuring out display from there, or writing/using a library which allows me to make and configure my own windows.

My question is, then, are those the best ways, or is there an easy way to output to multiple terminals simultaneously. Also, if making my own windows (and I'm sorry if my terminology is wrong when I say 'making my own windows'. I mean building my own output areas in Python) is the best option, I'm looking for which library I should use for that.


Solution

  • So you could go in multiple directions with this. You could create a Tkinter (or GUI library of your choice) output text box and write to that. This option would give you the most control over how to display your data.

    Another option is to access multiple terminals via named pipes. This involves spawning an xterm with a pipe and pumping output to it to be written on screen. See this question for and example:

    Using Python's Subprocess to Display Output in New Xterm Window