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

Stdin handling for terminals is broken on Windows #302

Closed
pfmoore opened this issue Jan 13, 2016 · 4 comments
Closed

Stdin handling for terminals is broken on Windows #302

pfmoore opened this issue Jan 13, 2016 · 4 comments
Labels
Milestone

Comments

@pfmoore
Copy link
Contributor

pfmoore commented Jan 13, 2016

I just created a simple tasks file on Windows:

from invoke import task, run
@task
def foo():
    print("Hello, world!")
    run("echo Hi")

When I try to run it (invoke 0.12.0, Python 3.5.0 64-bit) on Windows 7, I get the following error:

>inv foo
Hello, world!
Hi
Traceback (most recent call last):
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\UK03306\AppData\Local\Programs\Python\Python35\Scripts\inv.exe\__main__.py", line 9, in <module>
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\program.py", line 270, in run
    self.execute()
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\program.py", line 379, in execute
    executor.execute(*self.tasks)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\executor.py", line 114, in execute
    result = call.task(*args, **call.kwargs)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\tasks.py", line 113, in __call__
    result = self.body(*args, **kwargs)
  File "C:\Work\Scratch\tasks.py", line 5, in foo
    run("echo Hi")
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\__init__.py", line 27, in run
    return Context().run(command, **kwargs)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\context.py", line 53, in run
    return runner_class(context=self).run(command, **kwargs)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\runners.py", line 232, in run
    raise ThreadException(exceptions)
invoke.exceptions.ThreadException:
Saw 1 exceptions within threads (OSError):


Thread args: {'kwargs': {'input_': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp437'>},
 'target': <bound method Runner.handle_stdin of <invoke.runners.Local object at 0x0000000002FDA780>>}

Traceback (most recent call last):

  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\runners.py", line 804, in run
    super(_IOThread, self).run()

  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\threading.py", line 871, in run
    self._target(*self._args, **self._kwargs)

  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\runners.py", line 411, in handle_stdin
    reads, _, _ = select.select([input_], [], [], 0.0)

OSError: [WinError 10093] Either the application has not called WSAStartup, or WSAStartup failed

Note that the task output appears fine, so it's not clear what's going on here. Is it possible that invoke is trying to use select.select on sys.stdin? That's not allowed on Windows, you can only use select on sockets...

@pfmoore
Copy link
Contributor Author

pfmoore commented Jan 13, 2016

Yes, confirmed. Runner.handle_stdin sets use_select when isatty(input_) is true. That's what triggers trying to use select on a non-socket stream. But simply using False for use_select breaks, as the program hangs waiting for input, and then fails in write_stdin.

@pfmoore pfmoore changed the title select/threading error on Windows Stdin handling for terminals is broken on Windows Jan 14, 2016
@pfmoore
Copy link
Contributor Author

pfmoore commented Jan 14, 2016

PR #304 seems to fix this (based on a relatively straightforward test). At least for simple cases, run() is no longer totally broken on Windows.

Note that I'd view this as a critical fix - with this bug, invoke 0.12.0 is essentially unusable on Windows.

@presidento
Copy link
Contributor

👍

@bitprophet
Copy link
Member

Should be fixed as per discussions in #289 and #304.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants