Stdin handling for terminals is broken on Windows #302

pfmoore opened this Issue Jan 13, 2016 · 4 comments


None yet

3 participants

pfmoore commented Jan 13, 2016

I just created a simple tasks file on Windows:

from invoke import task, run
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!
Traceback (most recent call last):
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\UK03306\AppData\Local\Programs\Python\Python35\Scripts\inv.exe\", line 9, in <module>
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\", line 270, in run
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\", line 379, in execute
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\", line 114, in execute
    result = call.task(*args, **call.kwargs)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\", line 113, in __call__
    result = self.body(*args, **kwargs)
  File "C:\Work\Scratch\", line 5, in foo
    run("echo Hi")
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\", line 27, in run
    return Context().run(command, **kwargs)
  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\", 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\", line 232, in run
    raise ThreadException(exceptions)
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\", line 804, in run
    super(_IOThread, self).run()

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

  File "c:\users\uk03306\appdata\local\programs\python\python35\lib\site-packages\invoke\", line 411, in handle_stdin
    reads, _, _ =[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 on sys.stdin? That's not allowed on Windows, you can only use select on sockets...

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 from select/threading error on Windows to Stdin handling for terminals is broken on Windows Jan 14, 2016
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.



@bitprophet bitprophet added the Bug label Jan 20, 2016
@bitprophet bitprophet added this to the 0.12.1 milestone Jan 20, 2016

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

@bitprophet bitprophet closed this Jan 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment