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 beep: flush the output buffer #27

Merged
merged 1 commit into from
Nov 30, 2015
Merged

Conversation

blueyed
Copy link
Collaborator

@blueyed blueyed commented Nov 29, 2015

It works when using it through --onfail 'python -c "print(\"\a\", end=\"\")";', but not with the default options (without --nobeep).

I am not sure why that is required?!

I am using Python 3.5.0.

@blueyed
Copy link
Collaborator Author

blueyed commented Nov 29, 2015

Oh, it does not work: I was still using the bell char in --onfail.

So, don't merge this, but it should be an issue instead.

@blueyed blueyed changed the title Use '{!r}'.format for the beep/bell character Issue: use '{!r}'.format for the beep/bell character Nov 29, 2015
With end='', the BEEP_CHARACTER would not get sent instantly.
@blueyed blueyed changed the title Issue: use '{!r}'.format for the beep/bell character Fix beep: flush the output buffer Nov 29, 2015
@joeyespo
Copy link
Owner

Ha! I just ran into this same issue in http://github.com/joeyespo/py-getch. Nice find.

The print(BEEP_CHARACTER, end='') line can actually stay as-is; this works across Python versions. Python 3.x added a flush argument to flush the output, but Python 2.7 doesn't have this, so the workaround is follow it by sys.stdout.flush() like you have.

# Works on both Python 2.7 and 3.x
print(BEEP_CHARACTER, end='')
sys.stdout.flush()

Is this ready?

@blueyed
Copy link
Collaborator Author

blueyed commented Nov 30, 2015

Yes, should be ready.
I've found out about the (too new) flush argument also, and when using sys.stdout.flush I've replaced the print also - seems to be more consistent.
Do you think it should be kept as print? Then feel free to amend when merging.

@joeyespo
Copy link
Owner

Gotcha. Yeah, will probably keep print to follow "There should be one-- and preferably only one --obvious way to do it" -- in this case, print out text. Someday the flush call can be replaced with a flush argument. (Probably years though haha.)

Thanks for the fix 😃

joeyespo added a commit that referenced this pull request Nov 30, 2015
Fix beep: flush the output buffer
@joeyespo joeyespo merged commit a623984 into joeyespo:master Nov 30, 2015
@blueyed blueyed deleted the fix-beep branch November 30, 2015 00:50
@pyup-bot pyup-bot mentioned this pull request Aug 17, 2016
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.

2 participants