embray / gappy

Python interface to GAP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stdout/err capture

embray opened this issue · comments

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.

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.