Getting references to objects without incrementing reference counters
Diez B. Roggisch
deets at web.de
Mon Nov 15 16:42:56 CET 2010
Artur Siekielski <artur.siekielski at gmail.com> writes:
> On Nov 15, 1:03 am, de... at web.de (Diez B. Roggisch) wrote:
>> You don't say what data you share, and if all of it is needed for each
>> child. So it's hard to suggest optimizations.
> Here is an example of such a problem I'm dealing with now: I'm
> building large index of words in memory, it takes 50% of RAM. After
> building it I want to enable querying it using multiple processors
> enabling fast handling of multiple clients at once (communication is
> done with sockets). So I create the index in the parent process and
> than fork children that handle client queries. But after a short time
> only traversing the index by children makes them use much memory,
> resulting shortly in Out Of Memory Errors.
>> And AFAIK there is no
>> built-in way of doing what you want. It's complex and error-prone.
> Having read-only objects is complex and error-prone?
Yes. Python has no built-in semantics for that. You can't declare an
object to be read-only. And if one wanted to implement that, you'd have
to make sure the object consists only of read-only attributes
itself. And circumvene a great deal of the dynamic features in python
(which you don't need for this usecase, but still are there)
More information about the Python-list