I found some problem when using umysql lib.
i use some db pool to reuse the connection obj.
In case gevent timeout during the connection obj searching data from db,then the connection obj can't get right data after. the testing code below,expecting to your solution.
-- coding:utf-8 --
author:Ewing
date:2014-2-20
''' sql here
CREATE DATABASE test;
CREATE TABLE IF NOT EXISTS tb_user (
UserId int(11) NOT NULL,
LastLoginTime int(11) NOT NULL,
PRIMARY KEY (UserId)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO tb_user (UserId, LastLoginTime) VALUES
(1, 1392859212);
'''
from gevent import monkey; monkey.patch_all()
import time
from gevent import Timeout
import umysql
c = umysql.Connection()
c.connect('10.1.1.18', 3306, 'root','think1dfh@RUNpadm', 'test', False, 'utf8')
looptime = 100000 # FOR TEST set 1 or 100000
def doing():
start = time.time()
for i in xrange(looptime):
sql = 'UPDATE tb_user SET LastLoginTime = %s WHERE UserId = 1'%int(time.time())
c.query(sql,())
runtime = time.time()-start
print 'do all runtime: %s'%runtime
def afterdoing():
sql = 'SELECT * FROM tb_user WHERE UserId = 1'
result_set = c.query(sql,())
print 'afterdoing result_set:',result_set #return (1L, 0L) case timeout then nomal
I found some problem when using umysql lib. i use some db pool to reuse the connection obj.
In case gevent timeout during the connection obj searching data from db,then the connection obj can't get right data after. the testing code below,expecting to your solution.
-- coding:utf-8 --
author:Ewing
date:2014-2-20
''' sql here CREATE DATABASE test; CREATE TABLE IF NOT EXISTS
tb_user
(UserId
int(11) NOT NULL,LastLoginTime
int(11) NOT NULL, PRIMARY KEY (UserId
) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;INSERT INTO
tb_user
(UserId
,LastLoginTime
) VALUES (1, 1392859212); '''from gevent import monkey; monkey.patch_all() import time from gevent import Timeout import umysql c = umysql.Connection() c.connect('10.1.1.18', 3306, 'root','think1dfh@RUNpadm', 'test', False, 'utf8')
looptime = 100000 # FOR TEST set 1 or 100000 def doing(): start = time.time() for i in xrange(looptime): sql = 'UPDATE tb_user SET LastLoginTime = %s WHERE UserId = 1'%int(time.time()) c.query(sql,()) runtime = time.time()-start print 'do all runtime: %s'%runtime
def afterdoing(): sql = 'SELECT * FROM tb_user WHERE UserId = 1' result_set = c.query(sql,()) print 'afterdoing result_set:',result_set #return (1L, 0L) case timeout then nomal
timeout = Timeout(1) timeout.start() try: doing() except Timeout: print 'Could not complete'
afterdoing()
print 'end'