[Python-Dev] PyFAQ: thread-safe interpreter operations (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Wed Nov 22 22:49:26 CET 2006


Nick Coghlan schrieb:

Martin v. Löwis wrote:

I personally consider it "good style" to rely on implementation details of CPython; Is there a 'do not' missing somewhere in there?

No - I really mean it. I can find nothing wrong with people relying on reference counting to close files, for example. It's a property of CPython, and not guaranteed in other Python implementations - yet it works in a well-defined way in CPython. Code that relies on that feature is not portable, but portability is only one goal in software development, and may be irrelevant for some projects.

Likewise, I see nothing wrong with people relying on .append on a list working "correctly" when used from two threads, even though the language specification does not guarantee that property.

Similarly, it's fine when people rely on the C type "int" to have 32-bits when used with gcc on x86 Linux. The C standard makes that implementation-defined, but this specific implementation made a choice that you can rely on.

Regards, Martin



More information about the Python-Dev mailing list