Ticket #4964: mysql_testing.py

File mysql_testing.py, 784 bytes (added by jsw, 3 years ago)

example which triggers the problem

Line 
1"""
2Example which triggers a re-connection issue in adbapi.
3Run with a mysql wait_timeout which is less than DELAY e.g. in /etc/my.ini:
4
5[mysqld]
6wait_timeout=2
7"""
8
9from twisted.enterprise import adbapi
10from twisted.internet import reactor
11from twisted.python import log
12import sys
13
14DELAY = 3
15
16dbpool = adbapi.ConnectionPool(
17        'MySQLdb', 
18        db='mysql', 
19        host='localhost', 
20        user='root', 
21        cp_noisy=True,
22        cp_reconnect=True,
23        cp_min=1,
24        cp_max=1
25)
26
27def select_something():
28    def p(r):
29        log.msg("query returned", r)
30        reactor.callLater(DELAY, select_something)
31    return dbpool.runQuery("select 'something'").addCallback(p)
32
33log.startLogging(sys.stdout)
34reactor.callLater(DELAY, select_something)
35reactor.run()