#27 unbuffered bytes I/O for py3
Opened 5 years ago by earthgecko. Modified 2 years ago
earthgecko/python-daemon py3_unbuffered_bytes_io  into  master

No commits found

This is a fairly simple method to handle #5 and addresses the concerns in #7 relating to the removal of the ‘buffering’ argument and is done in a compatible way to allow unbuffered text IO on 2.7 and use unbuffered bytes IO on 3.x

As far as what changes need to be made in the unit tests as asked in #7, I cannot find a test related specifically to the _open_streams_from_app_stream_paths function in https://pagure.io/python-daemon/blob/master/f/test/test_runner.py

The try and except method will make zero difference to all running instances of python-daemon, as they all run on 2.7 and the try method is the 2.7 pattern. Seeing as it cannot run on 3.x at this point (well as least 3.6 and 3.7, I have not tested 3.5 but I suspect it may be the same) the except handles these. This fixes the error on 3.6 and 3.7.

Instead of this anti-pattern (overbroad except clause), can you limit it to some specific exception type whose meaning relates to why we're catching that exception?

The existing code intentionally tries to make all the streams open in text mode. Can you re-work this to code that results in a stream that's open in text mode? (You may also need to add or modify test cases for the various conditions in opening that stream.)

Thanks for the contribution.

Seeing as it cannot run on 3.x at this point (well as least 3.6 and 3.7, I have not tested 3.5 but I suspect it may be the same) the except handles these.

It seems to be only some conditions that cause the reported error, so we'll need to make changes that keep the code working on Python 3 and ensure no new errors are introduced.

1 new commit added

  • Update daemon/runner.py
3 years ago

@bignose stream opened in text mode as requested.

Seeing as Python 2 is no longer supported (#44), the only change that is required to resolve this issue is to set buffering to 1 as in Python 3 buffering can only be switched off for binary mode, as per https://docs.python.org/3/library/functions.html#open this is why daemon errors on py3.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode)

1 new commit added

  • Update daemon/runner.py
3 years ago

@bignose seems like simple solution here and most wanted by Python 3.x users.

Thank you for remaining interested in this change.

Note that the daemon/runner.py example is not part of the python-daemon library, and that module is not being maintained. Currently it raises a DeprecationWarning; that module will be dropped from the library in a future version.

Metadata Update from @bignose:
- Pull-request tagged with: wishlist

2 years ago
Metadata