Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86150
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <skip.montanaro@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'context': 0.07; 'none:': 0.07; '22,': 0.09; 'appropriate.': 0.09; 'bits': 0.09; 'subject:method': 0.09; 'try:': 0.09; 'type,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'accepts': 0.16; 'exit.': 0.16; 'parameter:': 0.16; 'sqlite': 0.16; 'suggested,': 0.16; 'thread,': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'sorry,': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'class': 0.32; 'skip:m 30': 0.32; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'could': 0.34; 'subject:with': 0.35; "can't": 0.35; 'connection': 0.35; 'except': 0.35; 'received:google.com': 0.35; 'manager': 0.38; 'pm,': 0.38; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'close': 0.67; 'delegates': 0.74; 'attention': 0.75; '2015': 0.84; 'subject:try': 0.84; 'careful': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=csQv2EQuNwfEQ6xSAWS7H1lm6hpi7UTyfAeZOzEbgi8=; b=aruWOiLPrzQLA3q217IhMhseuSM1xHn5q0YoiqD4APz6FyUyvO5nYjDQkfZr7t06Vt eECwRklkxkz7/kjRfdY8h1PdNDHCS+KdGxdv4cD1esGUdw2ijIoCDnqnZefsLNRM7lPp uDhhC+tfn/HxvO9Ncr2plor9M9TckZ8CuL7MAsUJoatt0Qlrlgi32HF1YsiA/yTv7ncB EoFYhnKSO2NzcsF0ybomqjSU5NiYYiwm2497SljXPQzp+cgI9eBahH6bphFdHm66+9F6 RTit9hEyAuSZH60FYDWnWFwEVFCja2zUvPO31Qp0MjdztJRiSZLuNyMaXlf5R1VKbQpB EsAw== |
| MIME-Version | 1.0 |
| X-Received | by 10.60.133.203 with SMTP id pe11mr2061564oeb.26.1424632509267; Sun, 22 Feb 2015 11:15:09 -0800 (PST) |
| In-Reply-To | <mk8keahatht34gt0kq1ncmtaskdu2s3arc@4ax.com> |
| References | <6trfeate2ppvm1mcapgr0g4g2fd3vceab6@4ax.com> <mailman.18955.1424521415.18130.python-list@python.org> <mk8keahatht34gt0kq1ncmtaskdu2s3arc@4ax.com> |
| Date | Sun, 22 Feb 2015 13:15:09 -0600 |
| Subject | Re: try pattern for database connection with the close method |
| From | Skip Montanaro <skip.montanaro@gmail.com> |
| To | Mario Figueiredo <marfig@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | Python <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19025.1424633976.18130.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1424633976 news.xs4all.nl 2975 [2001:888:2000:d::a6]:52467 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86150 |
Show key headers only | View raw
On Sun, Feb 22, 2015 at 12:41 PM, Mario Figueiredo <marfig@gmail.com> wrote:
> The sqlite context manager doesn't close a database connection on
> exit. It only ensures, commits and rollbacks are performed.
Sorry, I haven't paid careful attention to this thread, so perhaps
this has already been suggested, however... Can't you write your own
class which delegates to the necessary sqlite3 bits and has a context
manager with the desired behavior? Thinking out loud, you could define
a ConnectionMgr class which accepts a sqlite3 connection as a
parameter:
class ConnectionMgr(object):
def __init__(self, conn):
self.conn = conn
def __enter__(self):
...
def __exit__(self, type, value, exception):
if self.conn is not None:
... close self.conn connection here ...
self.conn = None
def __getattr__(self, attr):
return getattr(self.conn, attr)
then...
try:
with MyConnection(lite.connect('data.db')) as db:
...
except lite.DatabaseError:
...
Might also have to __enter__ and __exit__ self.conn as appropriate.
Skip
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
try pattern for database connection with the close method Mario Figueiredo <marfig@gmail.com> - 2015-02-21 03:42 +0100
Re: try pattern for database connection with the close method Chris Kaynor <ckaynor@zindagigames.com> - 2015-02-20 18:59 -0800
Re: try pattern for database connection with the close method Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-21 12:22 +0000
Re: try pattern for database connection with the close method Mario Figueiredo <marfig@gmail.com> - 2015-02-22 19:41 +0100
Re: try pattern for database connection with the close method Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-22 19:07 +0000
Re: try pattern for database connection with the close method Mario Figueiredo <marfig@gmail.com> - 2015-02-23 00:25 +0100
Re: try pattern for database connection with the close method Skip Montanaro <skip.montanaro@gmail.com> - 2015-02-22 13:15 -0600
Re: try pattern for database connection with the close method Mario Figueiredo <marfig@gmail.com> - 2015-02-23 00:30 +0100
Re: try pattern for database connection with the close method Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-21 08:16 -0700
Re: try pattern for database connection with the close method Peter Otten <__peter__@web.de> - 2015-02-21 16:22 +0100
Re: try pattern for database connection with the close method Mario Figueiredo <marfig@gmail.com> - 2015-02-23 00:35 +0100
Re: try pattern for database connection with the close method Peter Otten <__peter__@web.de> - 2015-02-21 16:27 +0100
Re: try pattern for database connection with the close method Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-21 08:50 -0700
Re: try pattern for database connection with the close method Peter Otten <__peter__@web.de> - 2015-02-21 18:02 +0100
csiph-web