Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:module': 0.04; 'stuff.': 0.05; 'framework.': 0.07; 'pep': 0.07; 'to)': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'url:peps': 0.09; 'variables.': 0.09; 'allocate': 0.16; 'docs,': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'py3': 0.16; 'case.': 0.16; 'static': 0.16; 'seems': 0.20; 'header:In-Reply-To:1': 0.22; 'works.': 0.23; 'besides': 0.25; 'says': 0.25; '(or': 0.25; '3.0': 0.28; 'stefan': 0.29; 'updated': 0.29; 'module': 0.30; '3.x': 0.30; 'url:dev': 0.30; '(including': 0.30; 'too': 0.32; 'rather': 0.33; 'it.': 0.33; 'comment': 0.33; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'however,': 0.34; 'daniel': 0.34; 'etc.)': 0.34; 'project': 0.35; 'option.': 0.35; "isn't": 0.35; 'url:python': 0.37; 'depend': 0.37; 'but': 0.37; 'another': 0.38; 'received:org': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'somewhat': 0.38; 'header:Mime-Version:1': 0.39; 'i.e.': 0.39; "there's": 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'where': 0.40; 'your': 0.60; 'target': 0.61; 'back': 0.63; 'perfectly': 0.64; 'here.': 0.66; 'often.': 0.84; 'subject:local': 0.84; 'ugly,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Stefan Behnel Subject: Re: keeping local state in an C extension module Date: Thu, 30 Jun 2011 15:10:22 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: gsnc-frn5-de01.fw.telefonica.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1309439445 news.xs4all.nl 21761 [2001:888:2000:d::a6]:33204 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8604 Daniel Franke, 30.06.2011 13:37: > 2011/6/30 Stefan Behnel: >> There's a PEP for Py3 that enables this through a general framework. In >> general, to achieve this, you may want to allocate the module content >> (including types etc.) on the heap rather than statically. >> >> http://www.python.org/dev/peps/pep-3121/ > > Perfect! Unfortunately, it seems not to be available in 2.x, so > unusable for now. For the foreseeable future the project can not > depend on 3.x as many (internal) target systems are "stable", i.e. are > not updated besides security stuff. Yes, it's Py3 only. >> Take a look at PyCapsule, it may (or may not) be enough for your use case. > > Also a perfectly good solution - unfortunately the same comment about > 3.0 applies here. > > >> However, note the comment about Py_InitModule4() in the docs, where it says >> that the 'self' passing feature isn't used very often. You may or may not >> want to (or need to) use it. > > If there are too many hoops to jump through to get a reasonable > solution working for 2.[567], I might as well go back to > Py_InitModule() and static variables. It's somewhat ugly, but it > works. Py2.x has a PyCObject, basically the predecessor to PyCapsule. Writing your own little type is another option. Stefan