vercel / hyper

A terminal built on web technologies
https://hyper.is
MIT License
43.28k stars 3.52k forks source link

Python 2.7 sometimes yields IOError: [Errno 0] Error on Windows #2822

Open NiklasRosenstein opened 6 years ago

NiklasRosenstein commented 6 years ago

Issue

Printing to the console with Python 2 sometimes results in an IOError: [Errno 0] on Windows. This issue seems to appear only on Windows when opening a file for both reading and writing, quote:

When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.

Relevant StackOverflow answer here.

Running this script almost certainly causes the error at some point:

# py -2.7 test.py
for i in range(5000):
  print('foo')

Output:

[...]
foo
foo
fTraceback (most recent call last):
  File "test.py", line 5, in <module>
    print('foo')
IOError: [Errno 0] Error

I am using Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32. I can not reproduce this with any other terminal (tested Windows default terminal & ConEmu).

It appears as if the standard output was broken or handled incorrectly when running Python from inside a Hyper terminal. To me it seems this must have a root cause unrelated to Python. When that cause is found, feel free to rename the title of this issue.

chabou commented 6 years ago

Can you try to reproduce with our canary release (upcoming v2): https://zeit.co/blog/canary#hyper?

It should be fixed.

Stanzilla commented 6 years ago

Hey there, please try again with the new Hyper v2 release and open a new issue if the problem stills exists. Thank you!

danielsamuels commented 6 years ago

I'm able to confirm that this issue still appears in v2.0.0.

danielsamuels commented 6 years ago

If it helps, we've found that if my_command throws the error then winpty my_command sometimes fixes it (where my_command is whatever you're running).

Stanzilla commented 6 years ago

@danielsamuels would you say that it's a duplicate of https://github.com/zeit/hyper/issues/2888 then?

danielsamuels commented 6 years ago

No, because my session is considered to be a TTY:

16:17 $ if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi
terminal
NiklasRosenstein commented 6 years ago

I can also reproduce this issue with Hyper 2.0.0 (stable)

gonzalocasas commented 6 years ago

I can reproduce consistently on Hyper: 2.0.0 (stable), Plugins: none, OS: Windows 10, Python: 2.7. It does NOT happen on Python 3.6 for whatever reason.

The issue is triggered by the frequency of writes. The same test code with a sleep(0.08) inside the loop works for me. At first I thought this was a weird issue with my code, but I've eventually realized it's a problem in Hyper and one that is actually quite critical and forces me not to use it from time to time.

The exact same code works on cmd.

Screenshot of the code running on a hyper console: image

Screenshot of the same code running on Windows' cmd console: image

Pomoinytskyi commented 6 years ago

Maybe it would be helpful or direct you in right way. I had similar problem with Python 2.7 which i tried to debug in VS Code. Problem was in using Integrated terminal. VS Code uses it by default. I disabled it in launch configuration file. I has parameter configurations/console which can be "none", "integratedTerminal" and "externalTerminal". Using "none" or "externalTerminal"solves the problem.

gonzalocasas commented 6 years ago

I also use VS Code with none as console, but in this case, that seems unrelated.

Pomoinytskyi commented 6 years ago

@gonzalocasas I found this solution after reading this issue - https://github.com/Microsoft/vscode/issues/36630 Maybe it will help you.

gonzalocasas commented 6 years ago

Today, the Windows 10, version 1803 update rolled out, and the issue went away, so, I think this could be closed, since the problem really seems to be on the Windows level (as described in the issue linked by @Pomoinytskyi )

falconych commented 6 years ago

Same issue appears in Pycharm Integrated terminal while using python 2.7.14 PyCharm 2018.1 (Community Edition) Build #PC-181.4203.547, built on March 26, 2018 JRE: 1.8.0_152-release-1136-b20 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0 the only solution for now is: not to use integrated terminal

NiklasRosenstein commented 6 years ago

I also can no longer reproduce this issue (same Hyper version, same Python version). (edit Actually I used Hyper v2.0.0)