[PATCH 4 of 5] py3: stop subscripting socket.error

Matt Harbison mharbison72 at gmail.com
Sat Dec 15 23:58:13 EST 2018


On Mon, 10 Dec 2018 07:12:41 -0500, Yuya Nishihara <yuya at tcha.org> wrote:

> On Sun, 09 Dec 2018 23:39:33 -0500, Matt Harbison wrote:
>> I ended up with similar stdio errors trying to track down the bad http
>> status failures:
>>
>> Traceback (most recent call last):
>>    File "c:\Users\Matt\hg\mercurial\ui.py", line 1033, in _writenobuf
>>      dest.flush()
>> OSError: [WinError 1] Incorrect function
>>
>> During handling of the above exception, another exception occurred:
>>
>> Traceback (most recent call last):
>>    File "c:\Users\Matt\hg\mercurial\hgweb\server.py", line 192, in  
>> do_hgweb
>>      for chunk in self.server.application(env, self._start_response):
>>    File "c:\Users\Matt\hg\mercurial\hgweb\hgweb_mod.py", line 310, in
>> run_wsgi
>>      for r in self._runwsgi(req, res, repo):
>>    File "c:\Users\Matt\hg\mercurial\hgweb\hgweb_mod.py", line 430, in
>> _runwsgi
>>      return getattr(webcommands, cmd)(rctx)
>>    File "c:\Users\Matt\hg\mercurial\hgweb\webcommands.py", line 861, in
>> comparison
>>      context = parsecontext(web.config('web', 'comparisoncontext', '5'))
>>    File "c:\Users\Matt\hg\mercurial\hgweb\hgweb_mod.py", line 117, in  
>> config
>>      untrusted=untrusted)
>>    File "c:\Users\Matt\hg\mercurial\ui.py", line 517, in config
>>      untrusted=untrusted)
>>    File "c:\Users\Matt\hg\mercurial\ui.py", line 536, in _config
>>      self.develwarn(msg, 2, 'warn-config-unknown')
>>    File "c:\Users\Matt\hg\mercurial\ui.py", line 1790, in develwarn
>>      % (msg, fname, lineno, fmsg))
>>    File "c:\Users\Matt\hg\mercurial\ui.py", line 996, in write_err
>>      self._write(self._ferr, *args, **opts)
>>    File "c:\Users\Matt\hg\mercurial\ui.py", line 1006, in _write
>>      self._writenobuf(dest, *args, **opts)
>>    File "c:\Users\Matt\hg\mercurial\ui.py", line 1039, in _writenobuf
>>      raise error.StdioError(err)
>> mercurial.error.StdioError: [Errno 22] Incorrect function
>>
>> I see that there's a TODO for pycompat.{stdin,stdout,stderr} to use a
>> silly wrapper instead of .buffer.  But this feeble attempt didn't seem  
>> to
>> help:
>
> That's unrelated issue. A pseudo file object might not have .buffer, but  
> a
> real stdio object should have one.
>
> Perhaps, the underlying file descriptor would be messed up in Windows  
> way.
> If we can know that prior to calling write(), stdio fds can be  
> reattached to
> NUL. But I don't know if that's possible.

I'm not sure what to do with this info yet, but I just noticed that pager  
is also messed up on py3- the debug message about spawning the pager  
prints, but no output for the diff.  Use --pager=no, and it shows up.  So  
maybe there's a general problem with stdio of spawned children.

I've been wondering why we aren't spawning the server child process with  
stdout and stderr handles set to NUL.  I know on Unix, the child prints a  
bit of info before it starts listening.  But that never worked on Windows,  
and we've been abusing the lock file to convey error messages back to the  
parent.

> Another Py3 issue is that sys.stdin/stdout/stderr is None on pythonw.exe.
> IIRC, this can be worked around by attaching NUL to fd=0-2, and open  
> them.
>
>   nullfd = os.open(os.devnull, O_RDWR | O_BINARY)
>   os.dup2(nullfd, 0)
>   os.dup2(nullfd, 1)
>   os.dup2(nullfd, 2)
>   os.close(nullfd)
>   stdin = os.fdopen(0, 'rb')
>   stdout = os.fdopen(1, 'wb')
>   stderr = os.fdopen(2, 'wb')
>
> But it might break ui.isatty() since NUL is reported as a tty on Windows.


About NUL being a tty, maybe this will help?

	https://stackoverflow.com/a/3660125


More information about the Mercurial-devel mailing list