Sure. Here it is: Main server module: http://pastebin.com/yLuZr12S Here I'm building MySQL connection: http://pastebin.com/ega3S5ye This is imported into rpcinterface and items are retrieved: http://pastebin.com/tJpvS60c
And the class ConfigSql(Sql) I posted in first post of this thread. On Sat, May 25, 2013 at 6:50 PM, Roberto De Ioris <[email protected]> wrote: > > > Thanks for reply, > > > > processlit just shows 1 peer: > > mysql -e"show processlist;" > > | 103 | root | localhost | photodb_dev | Query | 0 | NULL | show > > processlist | > > > > I also compared result of "show global status" before and after start > > uWSGI > > server but found nothing significant, maybe only "Aborted_connects" - but > > it's in both cases. > > > > before starting uWSGI server: http://pastebin.com/HwNRFVZA > > after starting: http://pastebin.com/iRMsHxKG > > > > Tom > > > > It looks like connections are not persistent. > > Can you report the code calling the query ? > > > > > On Sat, May 25, 2013 at 5:53 PM, Roberto De Ioris <[email protected]> > > wrote: > > > >> > >> > Hi, > >> > > >> > I created postfork decorater to forking my config class for each > >> worker. > >> > In > >> > config class there is establishing mysql database connection in init. > >> > Everything seems to be working fine (selects working well) but mysql > >> "show > >> > global status" shows after starting uWSGI RPC server with 3 workers: > >> > Threads_cached 2 > >> > Threads_connected 1 > >> > Threads_created 3 > >> > Threads_running 1 > >> > > >> > Shouldn't be there "Threads_connected 3"? Or do I have something > >> wrong > >> in > >> > calling @postfork? > >> > > >> > Short examples: > >> > > >> > *file: server.py* > >> > from lib import config as configapp > >> > @postfork > >> > def init(): > >> > import __builtin__ > >> > __builtin__.ConfigPhotoserver = configapp.ConfigPhotoserver > >> > > >> > import rpcinterface as iface > >> > ... > >> > > >> > > >> > *file: rpcinterface.py: *there is no importing config, > >> ConfigPhotoserver > >> > is > >> > already in global scope (checked with: print globals()) > >> > def getGallery(): > >> > cfg = ConfigPhotoserver() > >> > conn = cfg.sql.conn > >> > > >> > > >> > c = conn.cursor() > >> > # .... etc > >> > > >> > *file config.py:* > >> > class ConfigPhotoserver: > >> > def __init__(self): > >> > # some init ConfigParser stuff ....etc > >> > > >> > self.sql = ConfigSql(parser) > >> > > >> > class ConfigSql(Sql): > >> > def __init__(self): > >> > # parsing values needed for connection ....etc > >> > > >> > self.connect() > >> > > >> > *file sql.py:* > >> > import* *MySQLdb > >> > class Sql(): > >> > def __init__(self): > >> > self.conn = False > >> > #enddef > >> > > >> > def connect(self): > >> > self.conn = \ > >> > MySQLdb.connect( > >> > user=self.user, \ > >> > host=self.host, \ > >> > passwd=self.password, \ > >> > db=self.database, \ > >> > unix_socket=self.socket > >> > ) > >> > > >> > return self.conn > >> > > >> > Maybe it is a bit complicated but it seemed to me as the best > >> solution: > >> if > >> > I want db connection was created after forking each worker (and to be > >> > write-safe) and not to pass param conn in each function that needs it. > >> > > >> > Thanks for any remarks :-) > >> > > >> > >> The 2 cached threads should confirm you the code is right. > >> > >> Does show processlist reports 3 peers ? > >> > >> > >> -- > >> Roberto De Ioris > >> http://unbit.it > >> _______________________________________________ > >> uWSGI mailing list > >> [email protected] > >> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi > >> > > _______________________________________________ > > uWSGI mailing list > > [email protected] > > http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi > > > > > -- > Roberto De Ioris > http://unbit.it > _______________________________________________ > uWSGI mailing list > [email protected] > http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi >
_______________________________________________ uWSGI mailing list [email protected] http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
