embray / gappy

Python interface to GAP
GNU General Public License v3.0
13 stars 5 forks source link

stdout/err capture #4

Open embray opened 3 years ago

embray commented 3 years ago

When calling GAP functions like Print() which print directly to standard I/O, although it works, it doesn't pass through Python's sys.stdout, so it can't be captured by other Python code that captures I/O. In particular, pytest can't correctly capture the output of doctests where this happens.

This might be something to fix in pytest (maybe there is a plugin or option for this but I can't find one). But it might still be better for integration with other Python code if standard I/O passed through the standard Python streams somehow rather than directly to the file descriptor.

embray commented 3 years ago

One way might be to direct GAP's stdout to a pipe, and have a thread to read from that pipe (esp. while running any GAP calls) and redirect it to sys.stdout. Using a pipe + thread would be advantageous over just capturing to a variable, so that calling GAP functions that progressively write something to the stream is actually streamed and not just output all at once when the call is completed.