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 Windows compatibility #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abraha2d
Copy link

@abraha2d abraha2d commented Apr 27, 2024

Fixes #33.

The SIGPIPE signal is not available on Windows, so its import fails on that platform.

Upon further investigation, the SIGPIPE signal is already handled by Python by default,
so the signal(SIGPIPE, SIG_DFL) call shouldn't actually do anything...

Currently untested on Windows, but did test that this change does not adversely affect Linux.
Will remove draft status once tested on Windows.

Changes tested on both Linux (Ubuntu 22.04, Python 3.10) and Windows (Windows 10, Python 3.12).

@abraha2d abraha2d marked this pull request as ready for review April 27, 2024 18:23
@@ -66,8 +65,6 @@ def main(argv: Optional[List[str]] = None) -> None:
if _file:
_ = flu(read_file(_file)).map(str.rstrip)
else:
# Do not raise exception for Broken Pipe
signal(SIGPIPE, SIG_DFL)
Copy link
Owner

Choose a reason for hiding this comment

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

this is necessary to resolve broken pipe exceptions on unix systems

how about

import platform
...

if platform.system() != 'Windows':
  from signal import SIG_DFL, SIGPIPE, signal
  signal(SIGPIPE, SIG_DFL)
...

Copy link
Author

@abraha2d abraha2d Apr 29, 2024

Choose a reason for hiding this comment

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

Sure, I think at that point it may be best to wrap with try/catch ImportError instead of explicitly checking platform... that way it'll continue to work on any other platforms that don't have SIGPIPE.

Do you have a way to reproduce the broken pipe exception on Unix? I tried a couple different ways but never got it to happen.

Copy link
Owner

Choose a reason for hiding this comment

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

try:

flu 'flu(count())' -i 'itertools:count' | head -n 1
Screenshot 2024-04-30 at 9 44 36 AM

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.

flupy CLI does not work on Windows
2 participants