[PATCH 1 of 4] util: add a simple poll utility

Matt Mackall mpm at selenic.com
Wed Jun 3 17:17:34 CDT 2015


On Wed, 2015-06-03 at 13:26 -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1432162805 18000
> #      Wed May 20 18:00:05 2015 -0500
> # Node ID 0521446e1c5934bf377d8c6bd8a48baad6b57ae1
> # Parent  d3b8690c4ecc2a60b8edd9f632f77824284b6027
> util: add a simple poll utility
> 
> We'll use it to detect when the a sshpeer have server output to be displayed.
> 
> The implementation is super basic because all case support is not the focus of
> this series.
> 
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -16,11 +16,11 @@ hide platform-specific details from the 
>  import i18n
>  _ = i18n._
>  import error, osutil, encoding, parsers
>  import errno, shutil, sys, tempfile, traceback
>  import re as remod
> -import os, time, datetime, calendar, textwrap, signal, collections
> +import os, time, datetime, calendar, textwrap, signal, collections, sys, select

Hmm, is it really possible that util doesn't import sys? Very nearby
signs point to no.

> +def poll(fds):
> +    """block until something happened on any filedescriptors
> +
> +    This is a generic helper that will check for any activity
> +    (read, write.  exception). return the list of touched file.
> +
> +    In unsupported case raise a NotImplementedError"""
> +    if os.name == 'nt': # we do not support windows yet.
> +        raise NotImplementedError()
> +    if any(sys.maxint <= f for f in fds):
> +        raise NotImplementedError()
> +    res = select.select(fds, fds, fds)
> +    return sorted(list(set(sum(res, []))))
> +

Please use posix.py and windows.py, rather than putting conditionals in
util.

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list