Skip to content

Commit

Permalink
Drop support of Python < 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
matusvalo committed Nov 12, 2021
1 parent 0713348 commit f7d960b
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 271 deletions.
18 changes: 4 additions & 14 deletions billiard/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,18 @@
import signal
import sys

import pickle as pypickle
try:
import cPickle as cpickle
except ImportError: # pragma: no cover
cpickle = None # noqa
import pickle

from .exceptions import RestartFreqExceeded
from .five import monotonic
from time import monotonic

pickle = cpickle or pypickle
pickle_load = pickle.load
pickle_loads = pickle.loads

# cPickle.loads does not support buffer() objects,
# but we can just create a StringIO and use load.
if sys.version_info[0] == 3:
from io import BytesIO
else:
try:
from cStringIO import StringIO as BytesIO # noqa
except ImportError:
from StringIO import StringIO as BytesIO # noqa
from io import BytesIO


SIGMAP = dict(
(getattr(signal, n), n) for n in dir(signal) if n.startswith('SIG')
Expand Down
50 changes: 7 additions & 43 deletions billiard/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import sys

from .five import range, zip_longest
from itertools import zip_longest

if sys.platform == 'win32':
try:
Expand All @@ -20,31 +20,15 @@
except ImportError: # pragma: no cover
resource = None

try:
from io import UnsupportedOperation
FILENO_ERRORS = (AttributeError, ValueError, UnsupportedOperation)
except ImportError: # pragma: no cover
# Py2
FILENO_ERRORS = (AttributeError, ValueError) # noqa
from io import UnsupportedOperation
FILENO_ERRORS = (AttributeError, ValueError, UnsupportedOperation)


if sys.version_info > (2, 7, 5):
buf_t, is_new_buffer = memoryview, True # noqa
else:
buf_t, is_new_buffer = buffer, False # noqa

if hasattr(os, 'write'):
__write__ = os.write

if is_new_buffer:

def send_offset(fd, buf, offset):
return __write__(fd, buf[offset:])

else: # Py<2.7.6

def send_offset(fd, buf, offset): # noqa
return __write__(fd, buf_t(buf, offset))
def send_offset(fd, buf, offset):
return __write__(fd, buf[offset:])

else: # non-posix platform

Expand Down Expand Up @@ -99,21 +83,6 @@ def fsdecode(filename):
del _fscodec


if sys.version_info[0] == 3:
bytes = bytes
else:
_bytes = bytes

# the 'bytes' alias in Python2 does not support an encoding argument.

class bytes(_bytes): # noqa

def __new__(cls, *args):
if len(args) > 1:
return _bytes(args[0]).encode(*args[1:])
return _bytes(*args)


def maybe_fileno(f):
"""Get object fileno, or :const:`None` if not defined."""
if isinstance(f, numbers.Integral):
Expand Down Expand Up @@ -191,13 +160,8 @@ def get_errno(exc):
try:
return exc.errno
except AttributeError:
try:
# e.args = (errno, reason)
if isinstance(exc.args, tuple) and len(exc.args) == 2:
return exc.args[0]
except AttributeError:
pass
return 0
return 0


try:
import _posixsubprocess
Expand Down
2 changes: 1 addition & 1 deletion billiard/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from . import AuthenticationError, BufferTooShort
from ._ext import _billiard
from .compat import setblocking, send_offset
from .five import monotonic
from time import monotonic
from .reduction import ForkingPickler

try:
Expand Down
2 changes: 1 addition & 1 deletion billiard/dummy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from threading import Lock, RLock, Semaphore, BoundedSemaphore
from threading import Event

from billiard.five import Queue
from queue import Queue

from billiard.connection import Pipe

Expand Down
191 changes: 0 additions & 191 deletions billiard/five.py

This file was deleted.

9 changes: 5 additions & 4 deletions billiard/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from . import util
from . import get_context

from .five import Queue, items, monotonic
from queue import Queue
from time import monotonic

__all__ = ['BaseManager', 'SyncManager', 'BaseProxy', 'Token']

Expand Down Expand Up @@ -641,7 +642,7 @@ def register(cls, typeid, callable=None, proxytype=None, exposed=None,
)

if method_to_typeid:
for key, value in items(method_to_typeid):
for key, value in method_to_typeid.items():
assert type(key) is str, '%r is not a string' % key
assert type(value) is str, '%r is not a string' % value

Expand Down Expand Up @@ -931,9 +932,9 @@ def __init__(self, **kwds):
self.__dict__.update(kwds)

def __repr__(self):
items = list(self.__dict__.items())
_items = list(self.__dict__.items())
temp = []
for name, value in items:
for name, value in _items:
if not name.startswith('_'):
temp.append('%s=%r' % (name, value))
temp.sort()
Expand Down
9 changes: 4 additions & 5 deletions billiard/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
TimeoutError,
WorkerLostError,
)
from .five import Empty, Queue, range, values, reraise, monotonic
from time import monotonic
from queue import Queue, Empty
from .util import Finalize, debug, warning

MAXMEM_USED_FMT = """\
Expand Down Expand Up @@ -1240,7 +1241,7 @@ def _join_exited_workers(self, shutdown=False):
elif sched_for and not sched_for._is_alive():
self.on_job_process_down(job, sched_for.pid)

for worker in values(cleaned):
for worker in cleaned.values():
if self.on_process_down:
if not shutdown:
self._process_cleanup_queues(worker)
Expand Down Expand Up @@ -1355,9 +1356,7 @@ def maintain_pool(self):
raise
except OSError as exc:
if get_errno(exc) == errno.ENOMEM:
reraise(MemoryError,
MemoryError(str(exc)),
sys.exc_info()[2])
raise MemoryError from exc
raise

def _setup_queues(self):
Expand Down
Loading

0 comments on commit f7d960b

Please sign in to comment.