Jim Gregory
2016-12-28 16:05:41 UTC
I've written a module to manage a connection to a MySQL database. I would
like to make a connection to the database on each request and disconnect
after the request. I've tried doing this:
from modules.database import myMySQL
db = myMySQL('bikesatw_accounting')
@hook('before_request')
def _connect_db():
db = myMySQL('bikesatw_accounting')
@hook('after_request')
def _close_db():
if db.conn.open:
db.close()
This will open the database on the first request, but on subsequent
requests I receive the following error:
File
"/home/me/Projects/local/lib/python2.7/site-packages/pymysql/cursors.py",
line 71, in _get_db
raise err.ProgrammingError("Cursor closed")
ProgrammingError: Cursor closed
I can do this using hooks? I'm aware of the Bottle-MySQL plugin, but I'd
prefer to use my own module.
--
like to make a connection to the database on each request and disconnect
after the request. I've tried doing this:
from modules.database import myMySQL
db = myMySQL('bikesatw_accounting')
@hook('before_request')
def _connect_db():
db = myMySQL('bikesatw_accounting')
@hook('after_request')
def _close_db():
if db.conn.open:
db.close()
This will open the database on the first request, but on subsequent
requests I receive the following error:
File
"/home/me/Projects/local/lib/python2.7/site-packages/pymysql/cursors.py",
line 71, in _get_db
raise err.ProgrammingError("Cursor closed")
ProgrammingError: Cursor closed
I can do this using hooks? I'm aware of the Bottle-MySQL plugin, but I'd
prefer to use my own module.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.