-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC: Reconfigure existing streams #78
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #78 +/- ##
==========================================
- Coverage 100% 91.45% -8.55%
==========================================
Files 3 5 +2
Lines 101 281 +180
==========================================
+ Hits 101 257 +156
- Misses 0 24 +24
Continue to review full report at Codecov.
|
ae14f2e is a slightly different approach, which is failing occasionally, especially with repeated use, but I expect we can get this working on Windows also. fingers crossed there is a minor problem in my file handling. Using 17174a3 would still be used, especially on non-Windows, but I didnt want to include lots of branching between two implementations. Very likely the eventual solution will need to dynamically choose the best method of injecting new streams into the existing streams, and possibly even fall back to the current Given how brittle this is, we probably need PyPy and other Python implementations in the CI before it lands, but no need to get ahead on that, as this |
f3ec6f9
to
63ad755
Compare
OK, so we definitely have something usable here, and #75 (comment) has yet another way to achieve the same which should be less brittle. ~~ There is some ugly logging happening in the repeated test case, but that just needs some cleaning up, ~~ (fixed) and the manual close tests appear to really close stdout which means the pytest output thereafter is lost or the process may even disappears, and there are a few other finicky details wrt fake-closing the real sys streams. Note unbuffered is the default on Python 3.7, but worth noting that Git Bash for Windows apparently causes Python 3.7 to go into buffered mode. Point being that if there are ugly cludges, or remaining scenarios where it doesnt work properly, they will be older Pythons, and we'll degrade gracefully of course. Definitely need PyPy and IronPython and Jython CI now so we can aim for high compatibility and document incompatibility where it isnt feasible (easily). |
d119807
to
334fcd7
Compare
Next trick is to detect when this isnt possible, such as when |
Creates compat.py with backport of contextlib.AbstractContextManager to Python 3.4, so that the external interface of StdioManager has a consistent MRO irrespective of the Python version.
StdioTupleBase combines MultiItemTuple and TupleContextManager, and provides properties `stdin`, `stdout` and `stderr` for literate referencing the three members of the tuple. MultiItemTuple provides _map(), _all() and _any() for iterables, with suppress versions able to ignore exceptions. Base TupleContextManager creates a consistent MRO of tuple and AbstractContextManager. ClosingStdioTuple is a sample context manager which performs close() on each item in the tuple. TextIOTuple requires items to be a TextIOBase. AnyIOTuple can be used to create either a TextIOTuple or a FakeIOTuple, depending on whether the items are all a TextIOBase. This will allow attaching different implementations to each. AnyIOTuple is used to capture `sys.__std*__` and `sys.std*` as they existed at module import.
General question -- how does bringing the "File" types of objects into things relate to the stream-reconfiguration machinery? |
Separately, please take a look at the two Projects I just created for the repo. It would really help my understanding if the higher-level concepts were curated in a way keeps all the related stuff together, regardless of how spread out they are around the various issues/PRs. |
Many existing stdio capture and wrapper streams are only partial implementations, most commonly missing `__enter__` and `__exit__`. When StdioManager needs to integrate those streams into its service it needs to suppress exceptions caused by those missing methods.
Also fix test_capture_stderr_warn: Use always filter
Azure jobs show the failure.
As expected, pypy3 is failing. It looks pretty easy to fix.
Hopefully #75 (comment) provides enough context. I've got a few things bunched up in this POC PR, which will feed back into new issues and new smaller PRs. I'll try to group them into projects. |
I may have found a way to diagnose
|
👍 classnames like
But, using |
On Debian:
IOW, it seems like if it's buffered (no
|
The detection is even more fundamental than that:
|
Implements #75
Sits on top of #76
Failing on Windows, and other contexts.
This would be optional, or auto-used when the environment is acceptable.