Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Old programmers never die, they just branch to a new address.


devel / comp.lang.python / Re: Trouble with defaults and timeout decorator

SubjectAuthor
o Re: Trouble with defaults and timeout decoratorMRAB

1
Re: Trouble with defaults and timeout decorator

<mailman.146.1687633602.23016.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=23710&group=comp.lang.python#23710

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: pyt...@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Trouble with defaults and timeout decorator
Date: Sat, 24 Jun 2023 20:03:34 +0100
Lines: 40
Message-ID: <mailman.146.1687633602.23016.python-list@python.org>
References: <CANy1k1gyTKbuyph23EHDSvvz0tNi4=S_etL+tzuvgW5KLwAMFA@mail.gmail.com>
<b18a9788-8ca2-82eb-2787-aeb0674b6964@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de y+a0oybTSzkKTRk1Ds2bDAyAoMUUd+dICQBQPU99DNkA==
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=KTO8HGVN;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'modules':
0.07; 'from:addr:python': 0.09; 'module.': 0.09;
'received:192.168.1.64': 0.09; 'timeout': 0.09; 'url-
ip:151.101.0.223/32': 0.09; 'url-ip:151.101.128.223/32': 0.09;
'url-ip:151.101.192.223/32': 0.09; 'url-ip:151.101.64.223/32':
0.09; 'import': 0.15; 'from:addr:mrabarnett.plus.com': 0.16;
'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:84.93': 0.16; 'received:84.93.230': 0.16;
'received:plus.net': 0.16; 'subject:Trouble': 0.16; 'url:project':
0.16; 'url:pypi': 0.16; 'wrote:': 0.16; 'to:addr:python-list':
0.20; 'skip:_ 10': 0.22; 'goal': 0.23; 'stuff': 0.25; 'tried':
0.26; 'port': 0.26; 'header:User-Agent:1': 0.30; 'default': 0.31;
'module': 0.31; 'python-list': 0.32; 'received:192.168.1': 0.32;
'but': 0.32; "i'm": 0.33; 'header:In-Reply-To:1': 0.34;
'applying': 0.36; "skip:' 10": 0.37; 'class': 0.37;
'received:192.168': 0.37; 'tell': 0.60; 'url-ip:151.101.0/24':
0.62; 'url-ip:151.101.128/24': 0.62; 'url-ip:151.101.192/24':
0.62; 'url-ip:151.101.64/24': 0.62; 'skip:t 40': 0.64; 'with:':
0.64; 'database': 0.80; 'password,': 0.84; 'say,': 0.84; 'skip:j
20': 0.84; 'exists': 0.91; 'turned': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1687633415; bh=RnLqsRAtBwvT+E3cnyU5kNmsl0rU2G/aXI6Jz7/2B/Y=;
h=Date:Subject:To:References:From:In-Reply-To;
b=KTO8HGVNDNFwJGr/Hk3r/ekbhigZ0RFgAf2JCwS1iCIDqQZKydIDSJL8jL809drAu
//lbIJGT2m65oHzuCgwdR2zTPlqCgU0kw8grdbEgLagapQ9aandrtoC4hdYwKHM94e
GxhK89xZFfjK+hl9oYysi47Pa5Cd/00nQj8C+VRKHqjHisxhvho3pvF0LwebmJpRFz
UfBotCM1KdVpW5okjNjPqvVaQ28pIThG6XauobSmeijAPn1CNRK9mD3giyz9rAQBcy
t3A4/GNQg6Uu5hTT5QeVOrPsG8USMfYJi6Tf1yCMVoCG/6bxyrODJhvjRvmtXUpFEe
nGRjF2Aj3C0Kw==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=P4wpOwMu c=1 sm=1 tr=0 ts=64973e07
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=CckQENj0AAAA:8 a=mr1POb4nhX-aFMUhlBEA:9 a=QEXdDO2ut3YA:10
a=-XWihg8NfbdYC9mmq4w4:22
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.12.0
Content-Language: en-GB
In-Reply-To: <CANy1k1gyTKbuyph23EHDSvvz0tNi4=S_etL+tzuvgW5KLwAMFA@mail.gmail.com>
X-CMAE-Envelope: MS4xfAPGZ7oGien5zCdJwLlZfQXhHYThOImNuh/OztY24yxZrlqhW603YcWLravD5lHbPj9y0riiDBM8gly73VNbBxOREsTNKjgHLmHqCHnLjbAEi3b7KNHG
aA4YmRFBiah41Rs+f69zLUmgARMmA34nBNlQGtB4luR50mfx5A8HPIaFpSiBnoF4c8kQA9dhC9eamFowtUJ3AgAtQw3e3/Nkt5E=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <b18a9788-8ca2-82eb-2787-aeb0674b6964@mrabarnett.plus.com>
X-Mailman-Original-References: <CANy1k1gyTKbuyph23EHDSvvz0tNi4=S_etL+tzuvgW5KLwAMFA@mail.gmail.com>
 by: MRAB - Sat, 24 Jun 2023 19:03 UTC

On 2023-06-24 17:18, Jason Friedman via Python-list wrote:
> I'm writing a database connectivity module to be used by other modules and
> leveraging the jaydebeapi module.
> From what I can tell jaydebeapi contains no built-in timeout capability, so
> then I turned to https://pypi.org/project/timeout-decorator/.
> My goal is to have a default timeout of, say, 10 seconds, which can be
> overridden by the caller.
>
>
> import jaydebeapi
> from timeout_decorator import timeout
>
> class Database:
> database_connection = None
> database_name, user_name, password, host, port = stuff
> timeout = None
>
> def __init__(self, timeout=10):
> self.timeout = timeout
>
> @timeout(self.timeout)
> def get_connection(self):
> if not self.database_connection:
> self.database_connection = jaydebeapi.connect(some_args)
> return self.database_connection
>
>
> The trouble occurs on line 12 with:
> NameError: name 'self' is not defined

The decorator is applied when the class is defined, but 'self' exists
only in 'Database.__init__' and 'Database.get_connection' when they are
called.

Have you tried applying the decorator "manually" in 'Database.__init__'?

def __init__(self, timeout=10):
self.timeout = timeout
self.get_connection = timeout(self.timeout)(self.get_connection)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor