From 21170a763941d6f9cd736f6060ccef94358a326d Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 5 Nov 2018 21:28:05 +0900 Subject: [PATCH] Deprecate waiter (#285) --- MySQLdb/connections.py | 14 ++++++++------ _mysql.c | 2 +- samples/waiter_gevent.py | 24 ------------------------ samples/waiter_meinheld.py | 19 ------------------- 4 files changed, 9 insertions(+), 50 deletions(-) delete mode 100644 samples/waiter_gevent.py delete mode 100644 samples/waiter_meinheld.py diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 8375cd0..10a0bf7 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -200,6 +200,10 @@ class Connection(_mysql.connection): # PEP-249 requires autocommit to be initially off autocommit = kwargs2.pop('autocommit', False) self.waiter = kwargs2.pop('waiter', None) + if self.waiter: + from warnings import warn + warn("waiter is deprecated and will be removed in 1.4.", + DeprecationWarning, 2) super(Connection, self).__init__(*args, **kwargs2) self.cursorclass = cursorclass @@ -325,12 +329,10 @@ class Connection(_mysql.connection): return s def begin(self): - """Explicitly begin a connection. Non-standard. - DEPRECATED: Will be removed in 1.3. - Use an SQL BEGIN statement instead.""" - from warnings import warn - warn("begin() is non-standard and will be removed in 1.4", - DeprecationWarning, 2) + """Explicitly begin a connection. + + This method is not used when autocommit=False (default). + """ self.query("BEGIN") if not hasattr(_mysql.connection, 'warning_count'): diff --git a/_mysql.c b/_mysql.c index 52f3283..bf85704 100644 --- a/_mysql.c +++ b/_mysql.c @@ -756,7 +756,7 @@ static int _mysql_ConnectionObject_clear( } static char _mysql_ConnectionObject_fileno__doc__[] = -"Return underlaying fd for connection"; +"Return underlaying fd for connection (deprecated)"; static PyObject * _mysql_ConnectionObject_fileno( diff --git a/samples/waiter_gevent.py b/samples/waiter_gevent.py deleted file mode 100644 index 698b915..0000000 --- a/samples/waiter_gevent.py +++ /dev/null @@ -1,24 +0,0 @@ -from __future__ import print_function -"""Demo using Gevent with mysqlclient.""" - -import gevent.hub -import MySQLdb - - -def gevent_waiter(fd, hub=gevent.hub.get_hub()): - hub.wait(hub.loop.io(fd, 1)) - - -def f(n): - conn = MySQLdb.connect(user='root', waiter=gevent_waiter) - cur = conn.cursor() - cur.execute("SELECT SLEEP(%s)", (n,)) - cur.execute("SELECT 1+%s", (n,)) - print(cur.fetchall()[0]) - - -gevent.spawn(f, 1) -gevent.spawn(f, 2) -gevent.spawn(f, 3) -gevent.spawn(f, 4) -gevent.sleep(5) diff --git a/samples/waiter_meinheld.py b/samples/waiter_meinheld.py deleted file mode 100644 index 838c915..0000000 --- a/samples/waiter_meinheld.py +++ /dev/null @@ -1,19 +0,0 @@ -import meinheld -import MySQLdb - - -def meinheld_waiter(fd): - meinheld.server.trampoline(fd, read=True, timeout=10) - - -def app(env, start): - cont = b"Hello, World\n" - conn = MySQLdb.connect(user="root", waiter=meinheld_waiter) - cur = conn.cursor() - cur.execute("SELECT SLEEP(2)") - start(b"200 OK", [('Content-Type', 'text/plain'), ('Content-Length', str(len(cont)))]) - return [cont] - - -meinheld.server.listen(("0.0.0.0", 8080)) -meinheld.server.run(app)