comparison mercurial/commandserver.py @ 49280:311fcc5a65f6

thirdparty: remove Python 2-specific selectors2 copy The selectors module was added in Python 3.4. Because we require Python 3.6, it will always be available. Therefore the selectors2 module is not imported. I?ve verified that the selectors2-specific workaround in commandserver.py is not necessary with the selectors module from the standard library. It returns an empty list if timeout was exceeded. The pytype directive was needed to silence the following error: File "/tmp/mercurial-ci/mercurial/worker.py", line 299, in _posixworker: No attribute 'close' on int [attribute-error] In Union[_typeshed.HasFileno, int] File "/tmp/mercurial-ci/mercurial/worker.py", line 299, in _posixworker: No attribute 'close' on _typeshed.HasFileno [attribute-error] In Union[_typeshed.HasFileno, int]
author Manuel Jacob <me@manueljacob.de>
date Sat, 28 May 2022 22:08:13 +0200
parents 642e31cb55f0
children ee4537e365c8
comparison
equal deleted inserted replaced
49279:127d33e63d1a 49280:311fcc5a65f6
8 8
9 import errno 9 import errno
10 import gc 10 import gc
11 import os 11 import os
12 import random 12 import random
13 import selectors
13 import signal 14 import signal
14 import socket 15 import socket
15 import struct 16 import struct
16 import traceback 17 import traceback
17
18 try:
19 import selectors
20
21 selectors.BaseSelector
22 except ImportError:
23 from .thirdparty import selectors2 as selectors
24 18
25 from .i18n import _ 19 from .i18n import _
26 from .pycompat import getattr 20 from .pycompat import getattr
27 from . import ( 21 from . import (
28 encoding, 22 encoding,
642 # for requests that are queued (connect()-ed, but haven't been 636 # for requests that are queued (connect()-ed, but haven't been
643 # accept()-ed), handle them before exit. otherwise, clients 637 # accept()-ed), handle them before exit. otherwise, clients
644 # waiting for recv() will receive ECONNRESET. 638 # waiting for recv() will receive ECONNRESET.
645 self._unlinksocket() 639 self._unlinksocket()
646 exiting = True 640 exiting = True
647 try: 641 events = selector.select(timeout=h.pollinterval)
648 events = selector.select(timeout=h.pollinterval)
649 except OSError as inst:
650 # selectors2 raises ETIMEDOUT if timeout exceeded while
651 # handling signal interrupt. That's probably wrong, but
652 # we can easily get around it.
653 if inst.errno != errno.ETIMEDOUT:
654 raise
655 events = []
656 if not events: 642 if not events:
657 # only exit if we completed all queued requests 643 # only exit if we completed all queued requests
658 if exiting: 644 if exiting:
659 break 645 break
660 continue 646 continue