Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8604
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Subject | Re: keeping local state in an C extension module |
| Date | 2011-06-30 15:10 +0200 |
| References | <CAJ+j52Ye6s02v7i7D+U-qNWCEFMc_gaOJJgV2Xjvd1TaovzMoQ@mail.gmail.com> <iuhj82$mgf$1@dough.gmane.org> <CAJ+j52YYLormXbmSfdT7fRxE4sO2UjMSSNQQgMkKDNY1PpufFQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.523.1309439445.1164.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: keeping local state in an C extension module Stefan Behnel <stefan_ml@behnel.de> - 2011-06-30 15:10 +0200
csiph-web