mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 19:31:54 +08:00
Deprecate waiter (#285)
This commit is contained in:
@ -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'):
|
||||
|
2
_mysql.c
2
_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(
|
||||
|
@ -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)
|
@ -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)
|
Reference in New Issue
Block a user