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 cac44d4

Browse filesBrowse files
committed
Add waiter samples.
1 parent 7e15cf8 commit cac44d4
Copy full SHA for cac44d4

File tree

Expand file treeCollapse file tree

2 files changed

+44
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-0
lines changed

‎samples/waiter_gevent.py

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import print_function
2+
"""Demo using Gevent with mysqlclient."""
3+
4+
import gevent.hub
5+
import select
6+
import MySQLdb
7+
8+
9+
def gevent_waiter(fd, hub=gevent.hub.get_hub()):
10+
hub.wait(hub.loop.io(fd, 1))
11+
12+
13+
def f(n):
14+
conn = MySQLdb.connect(user='root', waiter=gevent_waiter)
15+
cur = conn.cursor()
16+
cur.execute("SELECT SLEEP(%s)", (n,))
17+
cur.execute("SELECT 1+%s", (n,))
18+
print(cur.fetchall()[0])
19+
20+
21+
gevent.spawn(f, 1)
22+
gevent.spawn(f, 2)
23+
gevent.spawn(f, 3)
24+
gevent.spawn(f, 4)
25+
gevent.sleep(5)

‎samples/waiter_meinheld.py

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import meinheld
2+
import MySQLdb
3+
4+
5+
def meinheld_waiter(fd):
6+
meinheld.server.trampoline(fd, read=True, timeout=10)
7+
8+
9+
def app(env, start):
10+
cont = b"Hello, World\n"
11+
conn = MySQLdb.connect(user="root", waiter=meinheld_waiter)
12+
cur = conn.cursor()
13+
cur.execute("SELECT SLEEP(2)")
14+
start(b"200 OK", [('Content-Type', 'text/plain'), ('Content-Length', str(len(cont)))])
15+
return [cont]
16+
17+
18+
meinheld.server.listen(("0.0.0.0", 8080))
19+
meinheld.server.run(app)

0 commit comments

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