Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e15cf8

Browse filesBrowse files
committed
Add waiter to MySQLdb.Connection.
1 parent 5ba6080 commit 7e15cf8
Copy full SHA for 7e15cf8

File tree

Expand file treeCollapse file tree

1 file changed

+15
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-2
lines changed

‎MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class Connection(_mysql.connection):
6363
"""MySQL Database Connection Object"""
6464

6565
default_cursor = cursors.Cursor
66+
waiter = None
6667

6768
def __init__(self, *args, **kwargs):
6869
"""
69-
7070
Create a connection to the database. It is strongly recommended
7171
that you only use keyword parameters. Consult the MySQL C API
7272
documentation for more information.
@@ -150,9 +150,13 @@ class object, used to create cursors (keyword only)
150150
If True, autocommit is enabled.
151151
If None, autocommit isn't set and server default is used.
152152
153+
waiter
154+
Callable accepts fd as an argument. It is called after sending
155+
query and before reading response.
156+
This is useful when using with greenlet and async io.
157+
153158
There are a number of undocumented, non-standard methods. See the
154159
documentation for the MySQL C API for some hints on what they do.
155-
156160
"""
157161
from MySQLdb.constants import CLIENT, FIELD_TYPE
158162
from MySQLdb.converters import conversions
@@ -195,6 +199,7 @@ class object, used to create cursors (keyword only)
195199

196200
# PEP-249 requires autocommit to be initially off
197201
autocommit = kwargs2.pop('autocommit', False)
202+
self.waiter = kwargs2.pop('waiter', None)
198203

199204
super(Connection, self).__init__(*args, **kwargs2)
200205
self.cursorclass = cursorclass
@@ -266,6 +271,14 @@ def cursor(self, cursorclass=None):
266271
"""
267272
return (cursorclass or self.cursorclass)(self)
268273

274+
def query(self, query):
275+
if self.waiter is not None:
276+
self.send_query(query)
277+
self.waiter(self.fileno())
278+
self.read_query_result()
279+
else:
280+
_mysql.connection.query(self, query)
281+
269282
def __enter__(self):
270283
if self.get_autocommit():
271284
self.query("BEGIN")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.