Windows: using hg executable from an IDE results in python errors

Alexander Belchenko bialix at ukr.net
Thu Mar 20 16:06:34 CDT 2008


Patrick Mézard пишет:
> Alexander Belchenko a écrit :
>> I'm not Patrick but you need to test is fd hasattr fileno. When program running as
>> subprocess then pipes fd never had fileno. Because they're not real files.
> 
> Testing for fileno() availability cannot harm but I am not sure it will solved the issue here since we get a bad file descriptor issue rather than a missing attribute. I don't know how to check fileno() is valid, maybe it should be positive ? Do you know an easy way to test these kind of setup ?

In Bazaar VCS we exactly test for hasattr(fd, 'fileno') and only then change mode of stream. And it 
works perfectly for us. (And for me personally).

Here is excerpt of the code from bzrlib/commands.py:

             # force sys.stdout to be binary stream on win32
             if sys.platform == 'win32':
                 fileno = getattr(sys.stdout, 'fileno', None)
                 if fileno:
                     import msvcrt
                     msvcrt.setmode(fileno(), os.O_BINARY)

Of course, you can do it in your own way. It's just working example, nothing more.


More information about the Mercurial mailing list