Skip to content
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

Fix Unix Poll Method (Issue 82) #83

Merged
merged 5 commits into from
Aug 18, 2021
Merged

Conversation

sam-harding
Copy link
Contributor

For #82

Fixes Unix Poll Method to use eventmasks so that on MacOS 10.14.6 poll does not return True when the Read pipe channel reports it ready for output.

Fixes Unix Poll Method to use eventmasks so that on MacOS 10.14.6 poll does not return True when the Read pipe channel reports it ready for output.
@sam-harding sam-harding closed this Jul 9, 2021
Reworked Poll Eventmask to have a wider range of read only event flags.
@sam-harding sam-harding reopened this Jul 9, 2021
@noxdafox
Copy link
Owner

Hello,

Thanks for providing this. I am on vacation right now, I'll come back to this once back.

poll.register(self.reader, READ_ONLY_EVENTMASK)

# Convert from Seconds to Milliseconds
timeout = timeout * 1000 if timeout else timeout
Copy link
Owner

@noxdafox noxdafox Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is usually an antipattern to test for None objects treating them as booleans:
https://www.python.org/dev/peps/pep-0008/#programming-recommendations

In this case, for example, if by chance the unix_poll() function would be given a large string, you would end up multiplying it by a factor of 1000 most likely sending the program to OOM.

It is always recommended to test explicitly against None values.

timeout = timeout * 1000 if timeout is not None else None

Or more simply in this case:

if timeout is not None:
    timeout *= MILLISECONDS

...

MILLISECONDS = 1000

@sam-harding
Copy link
Contributor Author

sam-harding commented Aug 18, 2021

Thanks for the heads up! I have swapped the None anti-pattern. I did not add any checks for strings in this commit, so I suppose there is still a risk of large string issues. I am happy to refactor in a check to see if timeout is a number (int or float) if you want added safety.

@noxdafox
Copy link
Owner

No need to check for the input type. After all, Python is using dynamic typing on purpose.

Thanks for your contribution! I will bake a release this WE.

@noxdafox noxdafox merged commit 421474a into noxdafox:master Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants