Draco6slayer
Draco6slayer

Reputation: 53

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.

Upvotes: 5

Views: 8934

Answers (3)

Tyler Bowers
Tyler Bowers

Reputation: 19

I had this same issue so I made a program: github

Upvotes: 0

tdelaney
tdelaney

Reputation: 77337

I like @ebarr's answer, but a quick and dirty way to do it is to write to several files. You can then open multiple terminals and tail the files.

Upvotes: 4

ebarr
ebarr

Reputation: 7842

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

Upvotes: 4

Related Questions