[PATCH 2 of 2] commandserver: use selector2

Yuya Nishihara yuya at tcha.org
Sat Jul 15 02:56:34 EDT 2017


On Fri, 14 Jul 2017 20:27:27 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1500089181 25200
> #      Fri Jul 14 20:26:21 2017 -0700
> # Node ID a6545c15171810059596259f60574011184c3412
> # Parent  5664763de82b48ca6882bbb624d01d467b4920d0
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r a6545c151718
> commandserver: use selector2

> diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
> --- a/mercurial/commandserver.py
> +++ b/mercurial/commandserver.py
> @@ -23,4 +23,5 @@ from . import (
>      error,
>      pycompat,
> +    selectors2,
>      util,
>  )
> @@ -477,4 +478,6 @@ class unixforkingservice(object):
>          exiting = False
>          h = self._servicehandler
> +        selector = selectors2.DefaultSelector()
> +        selector.register(self._sock, selectors2.EVENT_READ)
>          while True:
>              if not exiting and h.shouldexit():
> @@ -487,5 +490,5 @@ class unixforkingservice(object):
>                  exiting = True
>              try:
> -                ready = select.select([self._sock], [], [], h.pollinterval)[0]
> +                ready = selector.select(timeout=h.pollinterval)
>                  if not ready:
>                      # only exit if we completed all queued requests

Perhaps we no longer need to catch select.error, but _syscall_wrapper() of
selectors2 seems to raise ETIMEDOUT depending on how timeout is detected.
Can you take a look?


More information about the Mercurial-devel mailing list