Dropped Python 2.5 and 3.1 support and the "futures" compatibility package
This commit is contained in:
parent
cb09ff1f52
commit
86ebe126e6
7
CHANGES
7
CHANGES
@ -1,3 +1,10 @@
|
|||||||
|
3.0.0
|
||||||
|
=====
|
||||||
|
|
||||||
|
- Dropped Python 2.5 and 3.1 support
|
||||||
|
- Removed the deprecated "futures" top level package
|
||||||
|
|
||||||
|
|
||||||
2.2.0
|
2.2.0
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
@ -15,9 +15,11 @@ from concurrent.futures._base import (FIRST_COMPLETED,
|
|||||||
wait,
|
wait,
|
||||||
as_completed)
|
as_completed)
|
||||||
from concurrent.futures.thread import ThreadPoolExecutor
|
from concurrent.futures.thread import ThreadPoolExecutor
|
||||||
|
import sys
|
||||||
|
|
||||||
# Jython doesn't have multiprocessing
|
|
||||||
try:
|
try:
|
||||||
from concurrent.futures.process import ProcessPoolExecutor
|
from concurrent.futures.process import ProcessPoolExecutor
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
# Jython doesn't have multiprocessing
|
||||||
|
if not sys.platform.startswith('java'):
|
||||||
|
raise
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
# Copyright 2009 Brian Quinlan. All Rights Reserved.
|
# Copyright 2009 Brian Quinlan. All Rights Reserved.
|
||||||
# Licensed to PSF under a Contributor Agreement.
|
# Licensed to PSF under a Contributor Agreement.
|
||||||
|
|
||||||
from __future__ import with_statement
|
import collections
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from concurrent.futures._compat import reraise
|
|
||||||
|
|
||||||
try:
|
|
||||||
from collections import namedtuple
|
|
||||||
except ImportError:
|
|
||||||
from concurrent.futures._compat import namedtuple
|
|
||||||
|
|
||||||
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
|
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
|
||||||
|
|
||||||
FIRST_COMPLETED = 'FIRST_COMPLETED'
|
FIRST_COMPLETED = 'FIRST_COMPLETED'
|
||||||
@ -233,7 +226,7 @@ def as_completed(fs, timeout=None):
|
|||||||
for f in fs:
|
for f in fs:
|
||||||
f._waiters.remove(waiter)
|
f._waiters.remove(waiter)
|
||||||
|
|
||||||
DoneAndNotDoneFutures = namedtuple(
|
DoneAndNotDoneFutures = collections.namedtuple(
|
||||||
'DoneAndNotDoneFutures', 'done not_done')
|
'DoneAndNotDoneFutures', 'done not_done')
|
||||||
def wait(fs, timeout=None, return_when=ALL_COMPLETED):
|
def wait(fs, timeout=None, return_when=ALL_COMPLETED):
|
||||||
"""Wait for the futures in the given sequence to complete.
|
"""Wait for the futures in the given sequence to complete.
|
||||||
@ -356,7 +349,7 @@ class Future(object):
|
|||||||
|
|
||||||
def __get_result(self):
|
def __get_result(self):
|
||||||
if self._exception:
|
if self._exception:
|
||||||
reraise(self._exception, self._traceback)
|
raise type(self._exception), self._exception, self._traceback
|
||||||
else:
|
else:
|
||||||
return self._result
|
return self._result
|
||||||
|
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
from keyword import iskeyword as _iskeyword
|
|
||||||
from operator import itemgetter as _itemgetter
|
|
||||||
import sys as _sys
|
|
||||||
|
|
||||||
|
|
||||||
def namedtuple(typename, field_names):
|
|
||||||
"""Returns a new subclass of tuple with named fields.
|
|
||||||
|
|
||||||
>>> Point = namedtuple('Point', 'x y')
|
|
||||||
>>> Point.__doc__ # docstring for the new class
|
|
||||||
'Point(x, y)'
|
|
||||||
>>> p = Point(11, y=22) # instantiate with positional args or keywords
|
|
||||||
>>> p[0] + p[1] # indexable like a plain tuple
|
|
||||||
33
|
|
||||||
>>> x, y = p # unpack like a regular tuple
|
|
||||||
>>> x, y
|
|
||||||
(11, 22)
|
|
||||||
>>> p.x + p.y # fields also accessable by name
|
|
||||||
33
|
|
||||||
>>> d = p._asdict() # convert to a dictionary
|
|
||||||
>>> d['x']
|
|
||||||
11
|
|
||||||
>>> Point(**d) # convert from a dictionary
|
|
||||||
Point(x=11, y=22)
|
|
||||||
>>> p._replace(x=100) # _replace() is like str.replace() but targets named fields
|
|
||||||
Point(x=100, y=22)
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Parse and validate the field names. Validation serves two purposes,
|
|
||||||
# generating informative error messages and preventing template injection attacks.
|
|
||||||
if isinstance(field_names, basestring):
|
|
||||||
field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas
|
|
||||||
field_names = tuple(map(str, field_names))
|
|
||||||
for name in (typename,) + field_names:
|
|
||||||
if not all(c.isalnum() or c=='_' for c in name):
|
|
||||||
raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name)
|
|
||||||
if _iskeyword(name):
|
|
||||||
raise ValueError('Type names and field names cannot be a keyword: %r' % name)
|
|
||||||
if name[0].isdigit():
|
|
||||||
raise ValueError('Type names and field names cannot start with a number: %r' % name)
|
|
||||||
seen_names = set()
|
|
||||||
for name in field_names:
|
|
||||||
if name.startswith('_'):
|
|
||||||
raise ValueError('Field names cannot start with an underscore: %r' % name)
|
|
||||||
if name in seen_names:
|
|
||||||
raise ValueError('Encountered duplicate field name: %r' % name)
|
|
||||||
seen_names.add(name)
|
|
||||||
|
|
||||||
# Create and fill-in the class template
|
|
||||||
numfields = len(field_names)
|
|
||||||
argtxt = repr(field_names).replace("'", "")[1:-1] # tuple repr without parens or quotes
|
|
||||||
reprtxt = ', '.join('%s=%%r' % name for name in field_names)
|
|
||||||
dicttxt = ', '.join('%r: t[%d]' % (name, pos) for pos, name in enumerate(field_names))
|
|
||||||
template = '''class %(typename)s(tuple):
|
|
||||||
'%(typename)s(%(argtxt)s)' \n
|
|
||||||
__slots__ = () \n
|
|
||||||
_fields = %(field_names)r \n
|
|
||||||
def __new__(_cls, %(argtxt)s):
|
|
||||||
return _tuple.__new__(_cls, (%(argtxt)s)) \n
|
|
||||||
@classmethod
|
|
||||||
def _make(cls, iterable, new=tuple.__new__, len=len):
|
|
||||||
'Make a new %(typename)s object from a sequence or iterable'
|
|
||||||
result = new(cls, iterable)
|
|
||||||
if len(result) != %(numfields)d:
|
|
||||||
raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
|
|
||||||
return result \n
|
|
||||||
def __repr__(self):
|
|
||||||
return '%(typename)s(%(reprtxt)s)' %% self \n
|
|
||||||
def _asdict(t):
|
|
||||||
'Return a new dict which maps field names to their values'
|
|
||||||
return {%(dicttxt)s} \n
|
|
||||||
def _replace(_self, **kwds):
|
|
||||||
'Return a new %(typename)s object replacing specified fields with new values'
|
|
||||||
result = _self._make(map(kwds.pop, %(field_names)r, _self))
|
|
||||||
if kwds:
|
|
||||||
raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
|
|
||||||
return result \n
|
|
||||||
def __getnewargs__(self):
|
|
||||||
return tuple(self) \n\n''' % locals()
|
|
||||||
for i, name in enumerate(field_names):
|
|
||||||
template += ' %s = _property(_itemgetter(%d))\n' % (name, i)
|
|
||||||
|
|
||||||
# Execute the template string in a temporary namespace and
|
|
||||||
# support tracing utilities by setting a value for frame.f_globals['__name__']
|
|
||||||
namespace = dict(_itemgetter=_itemgetter, __name__='namedtuple_%s' % typename,
|
|
||||||
_property=property, _tuple=tuple)
|
|
||||||
try:
|
|
||||||
exec(template, namespace)
|
|
||||||
except SyntaxError:
|
|
||||||
e = _sys.exc_info()[1]
|
|
||||||
raise SyntaxError(e.message + ':\n' + template)
|
|
||||||
result = namespace[typename]
|
|
||||||
|
|
||||||
# For pickling to work, the __module__ variable needs to be set to the frame
|
|
||||||
# where the named tuple is created. Bypass this step in enviroments where
|
|
||||||
# sys._getframe is not defined (Jython for example).
|
|
||||||
if hasattr(_sys, '_getframe'):
|
|
||||||
result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
if _sys.version_info[0] < 3:
|
|
||||||
def reraise(exc, traceback):
|
|
||||||
locals_ = {'exc_type': type(exc), 'exc_value': exc, 'traceback': traceback}
|
|
||||||
exec('raise exc_type, exc_value, traceback', {}, locals_)
|
|
||||||
else:
|
|
||||||
def reraise(exc, traceback):
|
|
||||||
# Tracebacks are embedded in exceptions in Python 3
|
|
||||||
raise exc
|
|
@ -43,20 +43,14 @@ Process #1..n:
|
|||||||
_ResultItems in "Request Q"
|
_ResultItems in "Request Q"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import with_statement
|
|
||||||
import atexit
|
import atexit
|
||||||
|
from concurrent.futures import _base
|
||||||
|
import Queue as queue
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import threading
|
import threading
|
||||||
import weakref
|
import weakref
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from concurrent.futures import _base
|
|
||||||
|
|
||||||
try:
|
|
||||||
import queue
|
|
||||||
except ImportError:
|
|
||||||
import Queue as queue
|
|
||||||
|
|
||||||
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
|
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
|
||||||
|
|
||||||
# Workers are created as daemon threads and processes. This is done to allow the
|
# Workers are created as daemon threads and processes. This is done to allow the
|
||||||
|
@ -3,19 +3,13 @@
|
|||||||
|
|
||||||
"""Implements ThreadPoolExecutor."""
|
"""Implements ThreadPoolExecutor."""
|
||||||
|
|
||||||
from __future__ import with_statement
|
|
||||||
import atexit
|
import atexit
|
||||||
|
from concurrent.futures import _base
|
||||||
|
import Queue as queue
|
||||||
import threading
|
import threading
|
||||||
import weakref
|
import weakref
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from concurrent.futures import _base
|
|
||||||
|
|
||||||
try:
|
|
||||||
import queue
|
|
||||||
except ImportError:
|
|
||||||
import Queue as queue
|
|
||||||
|
|
||||||
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
|
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
|
||||||
|
|
||||||
# Workers are created as daemon threads. This is done to allow the interpreter
|
# Workers are created as daemon threads. This is done to allow the interpreter
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
# Copyright 2009 Brian Quinlan. All Rights Reserved.
|
|
||||||
# Licensed to PSF under a Contributor Agreement.
|
|
||||||
|
|
||||||
"""Execute computations asynchronously using threads or processes."""
|
|
||||||
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
from concurrent.futures import (FIRST_COMPLETED,
|
|
||||||
FIRST_EXCEPTION,
|
|
||||||
ALL_COMPLETED,
|
|
||||||
CancelledError,
|
|
||||||
TimeoutError,
|
|
||||||
Future,
|
|
||||||
Executor,
|
|
||||||
wait,
|
|
||||||
as_completed,
|
|
||||||
ProcessPoolExecutor,
|
|
||||||
ThreadPoolExecutor)
|
|
||||||
|
|
||||||
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
|
|
||||||
|
|
||||||
warnings.warn('The futures package has been deprecated. '
|
|
||||||
'Use the concurrent.futures package instead.',
|
|
||||||
DeprecationWarning)
|
|
@ -1 +0,0 @@
|
|||||||
from concurrent.futures import ProcessPoolExecutor
|
|
@ -1 +0,0 @@
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
|
@ -1,13 +1,6 @@
|
|||||||
[wheel]
|
|
||||||
universal = 1
|
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
source-dir = docs
|
source-dir = docs
|
||||||
build-dir = build/sphinx
|
build-dir = build/sphinx
|
||||||
|
|
||||||
[upload_docs]
|
[upload_docs]
|
||||||
upload-dir = build/sphinx/html
|
upload-dir = build/sphinx/html
|
||||||
|
|
||||||
[metadata]
|
|
||||||
requires-dist =
|
|
||||||
multiprocessing; python_version == '2.5' and platform.python_implementation != 'Jython'
|
|
||||||
|
10
setup.py
10
setup.py
@ -1,13 +1,9 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
extras = {}
|
extras = {}
|
||||||
try:
|
try:
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
extras['zip_safe'] = False
|
extras['zip_safe'] = False
|
||||||
if sys.version_info < (2, 6) and os.name != 'java':
|
|
||||||
extras['install_requires'] = ['multiprocessing']
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
@ -19,15 +15,13 @@ setup(name='futures',
|
|||||||
maintainer='Alex Gronholm',
|
maintainer='Alex Gronholm',
|
||||||
maintainer_email='alex.gronholm+pypi@nextday.fi',
|
maintainer_email='alex.gronholm+pypi@nextday.fi',
|
||||||
url='https://github.com/agronholm/pythonfutures',
|
url='https://github.com/agronholm/pythonfutures',
|
||||||
packages=['futures', 'concurrent', 'concurrent.futures'],
|
packages=['concurrent', 'concurrent.futures'],
|
||||||
license='BSD',
|
license='BSD',
|
||||||
classifiers=['License :: OSI Approved :: BSD License',
|
classifiers=['License :: OSI Approved :: BSD License',
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
'Programming Language :: Python :: 2.5',
|
|
||||||
'Programming Language :: Python :: 2.6',
|
'Programming Language :: Python :: 2.6',
|
||||||
'Programming Language :: Python :: 2.7',
|
'Programming Language :: Python :: 2.7',
|
||||||
'Programming Language :: Python :: 3',
|
'Programming Language :: Python :: 2 :: Only'],
|
||||||
'Programming Language :: Python :: 3.1'],
|
|
||||||
**extras
|
**extras
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from __future__ import with_statement
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -8,6 +7,8 @@ import contextlib
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
from StringIO import StringIO
|
||||||
|
from test import test_support
|
||||||
|
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from concurrent.futures._base import (
|
from concurrent.futures._base import (
|
||||||
@ -18,21 +19,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
try:
|
|
||||||
from StringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from io import StringIO
|
|
||||||
|
|
||||||
try:
|
|
||||||
from test import test_support
|
|
||||||
except ImportError:
|
|
||||||
from test import support as test_support
|
|
||||||
|
|
||||||
try:
|
|
||||||
next
|
|
||||||
except NameError:
|
|
||||||
next = lambda x: x.next()
|
|
||||||
|
|
||||||
|
|
||||||
def reap_threads(func):
|
def reap_threads(func):
|
||||||
"""Use this function when threads are being used. This will
|
"""Use this function when threads are being used. This will
|
||||||
|
Loading…
Reference in New Issue
Block a user