Commit 913b18bc authored by Jason Madden's avatar Jason Madden

clean up os; fix fork_and_watch to pass the ref argument.

clean up resolver_ares
cleanup thread.
cleanup testrunner
cleanup pool.
clean up event
parent 69a53c64
......@@ -53,3 +53,5 @@ pyflakes:
- F821
# F401: unused import; same story
- F401
# F811: redefined function; same story
- F811
......@@ -13,6 +13,7 @@
- Update c-ares to version 1.11.0 (`release notes <https://raw.githubusercontent.com/c-ares/c-ares/cares-1_11_0/RELEASE-NOTES>`_).
- Remove module ``gevent.coros`` which was replaced by ``gevent.lock``
and has been deprecated since 1.0b2.
- The ``ref`` parameter to :func:`gevent.os.fork_and_watch` was being ignored.
1.1.0 (Mar 5, 2016)
===================
......
......@@ -12,7 +12,7 @@ This module implements cooperative SSL socket wrappers.
from __future__ import absolute_import
import ssl as __ssl__
_ssl = __ssl__._ssl
_ssl = __ssl__._ssl # pylint:disable=no-member
import errno
from gevent.socket import socket, timeout_default
......@@ -30,24 +30,24 @@ __implements__ = [
__imports__ = []
name = value = None
for name in dir(__ssl__):
if name in __implements__:
_name = _value = None
for _name in dir(__ssl__):
if _name in __implements__:
continue
if name.startswith('__'):
if _name.startswith('__'):
continue
if name == 'socket':
if _name == 'socket':
# SSLSocket *must* subclass gevent.socket.socket; see issue 597
continue
value = getattr(__ssl__, name)
globals()[name] = value
__imports__.append(name)
_value = getattr(__ssl__, _name)
globals()[_name] = _value
__imports__.append(_name)
del name, value
del _name, _value
__all__ = __implements__ + __imports__
orig_SSLContext = __ssl__.SSLContext
orig_SSLContext = __ssl__.SSLContext # pylint:disable=no-member
class SSLContext(orig_SSLContext):
......@@ -103,6 +103,8 @@ class SSLSocket(socket):
for Python 3.
"""
# pylint:disable=too-many-instance-attributes,too-many-public-methods
_gevent_sock_class = _contextawaresock
def __init__(self, sock=None, keyfile=None, certfile=None,
......@@ -113,7 +115,7 @@ class SSLSocket(socket):
suppress_ragged_eofs=True, npn_protocols=None, ciphers=None,
server_hostname=None,
_context=None):
# pylint:disable=too-many-locals,too-many-statements,too-many-branches
if _context:
self._context = _context
else:
......@@ -224,6 +226,7 @@ class SSLSocket(socket):
def read(self, len=1024, buffer=None):
"""Read up to LEN bytes and return them.
Return zero-length string on EOF."""
# pylint:disable=too-many-branches
self._checkClosed()
if not self._sslobj:
raise ValueError("Read on closed or unwrapped SSL socket.")
......@@ -584,8 +587,8 @@ def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv23, ca_certs=None):
If 'ca_certs' is specified, validate the server cert against it.
If 'ssl_version' is specified, use it in the connection attempt."""
host, port = addr
if (ca_certs is not None):
_, _ = addr
if ca_certs is not None:
cert_reqs = CERT_REQUIRED
else:
cert_reqs = CERT_NONE
......
......@@ -79,7 +79,7 @@ class _AbstractLinkable(object):
if link in self._links:
try:
link(self)
except:
except: # pylint:disable=bare-except
self.hub.handle_error((link, self), *sys.exc_info())
# Mark everything done
done.update(todo)
......@@ -114,6 +114,7 @@ class _AbstractLinkable(object):
self.unlink(switch)
def _wait_return_value(self, waited, wait_success):
# pylint:disable=unused-argument
return None
def _wait(self, timeout=None):
......@@ -388,6 +389,7 @@ class AsyncResult(_AbstractLinkable):
return self.get(block=False)
def _wait_return_value(self, waited, gotit):
# pylint:disable=unused-argument
# Always return the value. Since this is a one-shot event,
# no race condition should reset it.
return self.value
......
......@@ -140,6 +140,8 @@ def tp_write(fd, buf):
if hasattr(os, 'fork'):
# pylint:disable=function-redefined,redefined-outer-name
_raw_fork = os.fork
def fork_gevent():
......@@ -338,7 +340,7 @@ if hasattr(os, 'fork'):
if pid:
# parent
loop = loop or get_hub().loop
watcher = loop.child(pid)
watcher = loop.child(pid, ref=ref)
_watched_children[pid] = watcher
watcher.start(_on_child, watcher, callback)
return pid
......
......@@ -113,7 +113,7 @@ class IMapUnordered(Greenlet):
g.rawlink(self._on_result)
return g
def _run(self):
def _run(self): # pylint:disable=method-hidden
try:
func = self.func
for item in self.iterable:
......@@ -241,7 +241,7 @@ class GroupMappingMixin(object):
def apply_cb(self, func, args=None, kwds=None, callback=None):
"""
:meth:`apply` the given *func(\*args, \*\*kwds)*, and, if a *callback* is given, run it with the
:meth:`apply` the given *func(\\*args, \\*\\*kwds)*, and, if a *callback* is given, run it with the
results of *func* (unless an exception was raised.)
The *callback* may be called synchronously or asynchronously. If called
......@@ -555,11 +555,11 @@ class Group(GroupMappingMixin):
Kill all greenlets being tracked by this group.
"""
timer = Timeout._start_new_or_dummy(timeout)
try:
try:
while self.greenlets:
for greenlet in list(self.greenlets):
if greenlet not in self.dying:
if greenlet in self.dying:
continue
try:
kill = greenlet.kill
except AttributeError:
......
......@@ -8,7 +8,7 @@ import sys
from _socket import getservbyname, getaddrinfo, gaierror, error
from gevent.hub import Waiter, get_hub, string_types, text_type, integer_types, reraise, PY3
from gevent.socket import AF_UNSPEC, AF_INET, AF_INET6, SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, AI_NUMERICHOST, EAI_SERVICE, AI_PASSIVE
from gevent.ares import channel, InvalidIP
from gevent.ares import channel, InvalidIP # pylint:disable=import-error,no-name-in-module
__all__ = ['Resolver']
......@@ -101,6 +101,7 @@ class Resolver(object):
# "self.ares is not ares" means channel was destroyed (because we were forked)
def _lookup_port(self, port, socktype):
# pylint:disable=too-many-branches
socktypes = []
if isinstance(port, string_types):
try:
......@@ -146,6 +147,7 @@ class Resolver(object):
return port, socktypes
def _getaddrinfo(self, host, port, family=0, socktype=0, proto=0, flags=0):
# pylint:disable=too-many-locals,too-many-branches
if isinstance(host, text_type):
host = host.encode('idna')
elif not isinstance(host, str) or (flags & AI_NUMERICHOST):
......@@ -167,19 +169,19 @@ class Resolver(object):
ares = self.ares
if family == AF_UNSPEC:
values = Values(self.hub, 2)
ares.gethostbyname(values, host, AF_INET)
ares.gethostbyname(values, host, AF_INET6)
ares_values = Values(self.hub, 2)
ares.gethostbyname(ares_values, host, AF_INET)
ares.gethostbyname(ares_values, host, AF_INET6)
elif family == AF_INET:
values = Values(self.hub, 1)
ares.gethostbyname(values, host, AF_INET)
ares_values = Values(self.hub, 1)
ares.gethostbyname(ares_values, host, AF_INET)
elif family == AF_INET6:
values = Values(self.hub, 1)
ares.gethostbyname(values, host, AF_INET6)
ares_values = Values(self.hub, 1)
ares.gethostbyname(ares_values, host, AF_INET6)
else:
raise gaierror(5, 'ai_family not supported: %r' % (family, ))
values = values.get()
values = ares_values.get()
if len(values) == 2 and values[0] == values[1]:
values.pop()
......@@ -281,7 +283,7 @@ class Resolver(object):
reraise(*sys.exc_info())
elif len(result) != 1:
raise error('sockaddr resolved to multiple addresses')
family, socktype, proto, name, address = result[0]
family, _socktype, _proto, _name, address = result[0]
if family == AF_INET:
if len(sockaddr) != 2:
......@@ -331,7 +333,8 @@ class Values(object):
if self.values:
return self.values
else:
raise self.error
assert error is not None
raise self.error # pylint:disable=raising-bad-type
def _resolve_special(hostname, family):
......
......@@ -19,7 +19,7 @@ __implements__ = ['allocate_lock',
__imports__ = ['error']
if sys.version_info[0] <= 2:
import thread as __thread__
import thread as __thread__ # pylint:disable=import-error,useless-suppression
else:
import _thread as __thread__
__target__ = '_thread'
......@@ -43,8 +43,11 @@ def get_ident(gr=None):
return id(gr)
def start_new_thread(function, args=(), kwargs={}):
def start_new_thread(function, args=(), kwargs=None):
if kwargs is not None:
greenlet = Greenlet.spawn(function, *args, **kwargs)
else:
greenlet = Greenlet.spawn(function, *args)
return get_ident(greenlet)
......
......@@ -34,6 +34,7 @@ IGNORE_COVERAGE = [
def run_many(tests, expected=(), failfast=False):
# pylint:disable=too-many-locals
global NWORKERS
start = time.time()
total = 0
......@@ -71,7 +72,7 @@ def run_many(tests, expected=(), failfast=False):
while reap() > 0:
time.sleep(0.1)
def spawn(args, kwargs):
def spawn(args, kwargs): # pylint:disable=unused-argument
while True:
if reap() < NWORKERS:
r = pool.apply_async(run_one, (cmd, ), options or {})
......@@ -117,7 +118,7 @@ def run_many(tests, expected=(), failfast=False):
def discover(tests=None, ignore=(), coverage=False):
if isinstance(ignore, six.string_types):
ignore = load_list_from_file(ignore)
ignore = set(load_list_from_file(ignore))
ignore = set(ignore or ())
if coverage:
......@@ -194,6 +195,7 @@ def format_seconds(seconds):
def report(total, failed, passed, exit=True, took=None, expected=None):
# pylint:disable=redefined-builtin,too-many-branches
runtimelog = util.runtimelog
if runtimelog:
log('\nLongest-running tests:')
......@@ -253,7 +255,8 @@ def print_list(lst):
def main():
import optparse
# FIXME: transition to argparse
import optparse # pylint:disable=deprecated-module
parser = optparse.OptionParser()
parser.add_option('--ignore')
parser.add_option('--discover', action='store_true')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment