##// END OF EJS Templates
cleanup: directly use concurrent.futures instead of via pycompat...
Augie Fackler -
r49690:a0da5075 default
parent child Browse files
Show More
@@ -14,6 +14,7 b' import os'
14 import socket
14 import socket
15 import struct
15 import struct
16
16
17 from concurrent import futures
17 from .i18n import _
18 from .i18n import _
18 from .pycompat import getattr
19 from .pycompat import getattr
19 from . import (
20 from . import (
@@ -538,12 +539,12 b' class httppeer(wireprotov1peer.wirepeer)'
538 raise exception
539 raise exception
539
540
540
541
541 class queuedcommandfuture(pycompat.futures.Future):
542 class queuedcommandfuture(futures.Future):
542 """Wraps result() on command futures to trigger submission on call."""
543 """Wraps result() on command futures to trigger submission on call."""
543
544
544 def result(self, timeout=None):
545 def result(self, timeout=None):
545 if self.done():
546 if self.done():
546 return pycompat.futures.Future.result(self, timeout)
547 return futures.Future.result(self, timeout)
547
548
548 self._peerexecutor.sendcommands()
549 self._peerexecutor.sendcommands()
549
550
@@ -16,6 +16,7 b' import sys'
16 import time
16 import time
17 import weakref
17 import weakref
18
18
19 from concurrent import futures
19 from .i18n import _
20 from .i18n import _
20 from .node import (
21 from .node import (
21 bin,
22 bin,
@@ -278,7 +279,7 b' class localcommandexecutor(object):'
278 # method on the peer and return a resolved future.
279 # method on the peer and return a resolved future.
279 fn = getattr(self._peer, pycompat.sysstr(command))
280 fn = getattr(self._peer, pycompat.sysstr(command))
280
281
281 f = pycompat.futures.Future()
282 f = futures.Future()
282
283
283 try:
284 try:
284 result = fn(**pycompat.strkwargs(args))
285 result = fn(**pycompat.strkwargs(args))
@@ -35,8 +35,6 b' if not ispy3:'
35 import SocketServer as socketserver
35 import SocketServer as socketserver
36 import xmlrpclib
36 import xmlrpclib
37
37
38 from .thirdparty.concurrent import futures
39
40 def future_set_exception_info(f, exc_info):
38 def future_set_exception_info(f, exc_info):
41 f.set_exception_info(*exc_info)
39 f.set_exception_info(*exc_info)
42
40
@@ -45,7 +43,6 b' if not ispy3:'
45
43
46 else:
44 else:
47 import builtins
45 import builtins
48 import concurrent.futures as futures
49 import http.cookiejar as cookielib
46 import http.cookiejar as cookielib
50 import http.client as httplib
47 import http.client as httplib
51 import pickle
48 import pickle
@@ -10,6 +10,7 b' from __future__ import absolute_import'
10 import sys
10 import sys
11 import weakref
11 import weakref
12
12
13 from concurrent import futures
13 from .i18n import _
14 from .i18n import _
14 from .node import bin
15 from .node import bin
15 from .pycompat import (
16 from .pycompat import (
@@ -88,7 +89,7 b' def encodebatchcmds(req):'
88 return b';'.join(cmds)
89 return b';'.join(cmds)
89
90
90
91
91 class unsentfuture(pycompat.futures.Future):
92 class unsentfuture(futures.Future):
92 """A Future variation to represent an unsent command.
93 """A Future variation to represent an unsent command.
93
94
94 Because we buffer commands and don't submit them immediately, calling
95 Because we buffer commands and don't submit them immediately, calling
@@ -99,7 +100,7 b' class unsentfuture(pycompat.futures.Futu'
99
100
100 def result(self, timeout=None):
101 def result(self, timeout=None):
101 if self.done():
102 if self.done():
102 return pycompat.futures.Future.result(self, timeout)
103 return futures.Future.result(self, timeout)
103
104
104 self._peerexecutor.sendcommands()
105 self._peerexecutor.sendcommands()
105
106
@@ -154,7 +155,7 b' class peerexecutor(object):'
154 # a batchable one and refuse to service it.
155 # a batchable one and refuse to service it.
155
156
156 def addcall():
157 def addcall():
157 f = pycompat.futures.Future()
158 f = futures.Future()
158 self._futures.add(f)
159 self._futures.add(f)
159 self._calls.append((command, args, fn, f))
160 self._calls.append((command, args, fn, f))
160 return f
161 return f
@@ -194,7 +195,7 b' class peerexecutor(object):'
194 # cycle between us and futures.
195 # cycle between us and futures.
195 for f in self._futures:
196 for f in self._futures:
196 if isinstance(f, unsentfuture):
197 if isinstance(f, unsentfuture):
197 f.__class__ = pycompat.futures.Future
198 f.__class__ = futures.Future
198 f._peerexecutor = None
199 f._peerexecutor = None
199
200
200 calls = self._calls
201 calls = self._calls
@@ -258,7 +259,7 b' class peerexecutor(object):'
258 # hard and it is easy to encounter race conditions, deadlocks, etc.
259 # hard and it is easy to encounter race conditions, deadlocks, etc.
259 # concurrent.futures already solves these problems and its thread pool
260 # concurrent.futures already solves these problems and its thread pool
260 # executor has minimal overhead. So we use it.
261 # executor has minimal overhead. So we use it.
261 self._responseexecutor = pycompat.futures.ThreadPoolExecutor(1)
262 self._responseexecutor = futures.ThreadPoolExecutor(1)
262 self._responsef = self._responseexecutor.submit(
263 self._responsef = self._responseexecutor.submit(
263 self._readbatchresponse, states, wireresults
264 self._readbatchresponse, states, wireresults
264 )
265 )
General Comments 0
You need to be logged in to leave comments. Login now