Mercurial > hg-stable
annotate mercurial/thirdparty/concurrent/futures/__init__.py @ 37623:eb687c28a915
thirdparty: vendor futures 3.2.0
Python 3 has a concurrent.futures package in the standard library
for representing futures. The "futures" package on PyPI is a backport
of this package to work with Python 2.
The wire protocol code today has its own future concept for handling
of "batch" requests. The frame-based protocol will also want to
use futures.
I've heavily used the "futures" package on Python 2 in other projects
and it is pretty nice. It even has a built-in thread and process pool
for running functions in parallel. I've used this heavily for concurrent
I/O and other GIL-less activities.
The existing futures API in the wire protocol code is not as nice as
concurrent.futures. Since concurrent.futures is in the Python standard
library and will presumably be the long-term future for futures in our
code base, let's vendor the backport so we can use proper futures today.
# no-check-commit because of style violations
Differential Revision: https://phab.mercurial-scm.org/D3261
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 11 Apr 2018 14:48:24 -0700 |
parents | |
children | 0a9c0d3480b2 |
rev | line source |
---|---|
37623
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # Copyright 2009 Brian Quinlan. All Rights Reserved. |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # Licensed to PSF under a Contributor Agreement. |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 """Execute computations asynchronously using threads or processes.""" |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 __author__ = 'Brian Quinlan (brian@sweetapp.com)' |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 from concurrent.futures._base import (FIRST_COMPLETED, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 FIRST_EXCEPTION, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 ALL_COMPLETED, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 CancelledError, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 TimeoutError, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 Future, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 Executor, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 wait, |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 as_completed) |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 from concurrent.futures.thread import ThreadPoolExecutor |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 try: |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 from concurrent.futures.process import ProcessPoolExecutor |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 except ImportError: |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 # some platforms don't have multiprocessing |
eb687c28a915
thirdparty: vendor futures 3.2.0
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 pass |