Changes between Version 38 and Version 39 of DjangoSpecifications/Core/Threading


Ignore:
Timestamp:
Apr 26, 2008, 2:51:19 PM (17 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DjangoSpecifications/Core/Threading

    v38 v39  
    108108 1. `django/db/models/fields/related.py`: `append()` in `add_lazy_relation()` can add duplicated values, which may or may not confuse `pop()` in `do_pending_lookups()`
    109109
    110 === Raw `grep` results ===
    111 
    112 ==== Globals accessed with the `global` keyword ====
     110
     111== Class attributes ==
     112
     113Class attributes are shared between instances and thus between threads as well
     114(as module-level classes are just global class objects).
     115
     116The behaviour is similar to globals: in similar manner to the global keyword in
     117functions, explicit class specifier `foo.__class__.bar` is required for setting
     118class variable `bar` from instance `foo`, otherwise a instance scope variable
     119will be created that hides the class scope variable.
     120
     121(As this may not be obvious, let me illustrate it:)
     122{{{
     123>>> class Foo(object): bar = 1
     124...
     125>>> f = Foo()
     126>>> f.bar = 2
     127>>> Foo.bar
     1281
     129>>> f.bar
     1302
     131>>> f.__class__.bar
     1321
     133>>> f.__class__.bar = 3
     134>>> f.bar
     1352
     136>>> Foo.bar
     1373
     138}}}
     139
     140As with globals,
     141 1. class variables that are assigned to when the class is defined and never modified later (THREAD-SAFE),
     142 1. mutable class level data structures (lists and dictionaries, also instances) that are assigned to when the class is defined but whose elements are modified in methods and that are accessed without using the `__class__` keyword (NOT THREAD-SAFE),
     143 1. class variables assigned to in methods by using the `__class__` keyword (NOT THREAD-SAFE),
     144
     145Metaclasses -- think through the implications.
     146
     147== Raw `grep` results ==
     148
     149=== Globals accessed with the `global` keyword ===
    113150
    114151{{{
     
    133170Out of these, `django.core.management` is not used in multi-threading context.
    134171
    135 ==== Global dictionaries ====
     172=== Global dictionaries ===
    136173
    137174{{{
     
    219256}}}
    220257
    221 ==== Global lists ====
     258=== Global lists ===
    222259
    223260{{{
     
    248285As a matter of style, the read-only ones should really be tuples, not lists -- the 'say what you mean' idiom: if it shouldn't be modified, don't let it be by making it a tuple. Tuples are also marginally more efficient speed- and space-wise. There is a slight semantic distinction between lists and tuples though http://jtauber.com/blog/2006/04/15/python_tuples_are_not_just_constant_lists/ . But as there are no constant lists in Python, tuples are the only way to be const-correct.
    249286
    250 == Class attributes ==
    251 
    252 Class attributes are shared between instances and thus between threads as well
    253 (as module-level classes are just global class objects).
    254 
    255 The behaviour is similar to globals: in similar manner to the global keyword in
    256 functions, explicit class specifier `foo.__class__.bar` is required for setting
    257 class variable `bar` from instance `foo`, otherwise a instance scope variable
    258 will be created that hides the class scope variable.
    259 
    260 (As this may not be obvious, let me illustrate it:)
    261 {{{
    262 >>> class Foo(object): bar = 1
    263 ...
    264 >>> f = Foo()
    265 >>> f.bar = 2
    266 >>> Foo.bar
    267 1
    268 >>> f.bar
    269 2
    270 >>> f.__class__.bar
    271 1
    272 >>> f.__class__.bar = 3
    273 >>> f.bar
    274 2
    275 >>> Foo.bar
    276 3
    277 }}}
    278 
    279 As with globals,
    280  1. class variables that are assigned to when the class is defined and never modified later (THREAD-SAFE),
    281  1. mutable class level data structures (lists and dictionaries, also instances) that are assigned to when the class is defined but whose elements are modified in methods and that are accessed without using the `__class__` keyword (NOT THREAD-SAFE),
    282  1. class variables assigned to in methods by using the `__class__` keyword (NOT THREAD-SAFE),
    283 
    284 Metaclasses -- think through the implications.
    285 
    286 === Raw `grep` results ===
    287 
    288 ==== `__class__` keyword used for accessing anything other than `__name__` ====
     287=== `__class__` keyword used for accessing anything other than `__name__` ===
    289288
    290289{{{
Back to Top