Changes between Version 14 and Version 15 of DjangoSpecifications/Core/Threading


Ignore:
Timestamp:
04/14/2008 02:27:47 AM (7 years ago)
Author:
mrts
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DjangoSpecifications/Core/Threading

    v14 v15  
    2121 1. global mutable data structures (lists and dictionaries, also instances) that are assigned to at module level but whose elements are modified in functions and that are accessed without using the `global` keyword (NOT THREAD-SAFE unless never modified).
    2222
     23"Not thread-safe" has two broad subcategories:
     24 * inefficiencies due to calls meant to occur only once occurring more than once (the general `if not foo: initialize foo`, including `memoize` decorator),
     25 * errors due to incomplete initialization.
     26
     27Incomplete initialization errors can generally be avoided by using full
     28assignment instead of elementwise modification (that's how it is done in the
     29source mostly). That is,
     30
     31'''BAD'''
     32{{{
     33foo = []
     34def bar():
     35   ...
     36   if not foo:
     37      for x in y:
     38         foo.append(x)
     39}}}
     40
     41'''BETTER'''
     42{{{
     43foo = []
     44def bar():
     45   ...
     46   global foo
     47   if not foo:
     48      tmp = []
     49      for x in y:
     50         tmp.append(x)
     51      foo = tmp # atomic assignment
     52}}}
     53
    2354The following modules' use of globals needs review.
    2455
     
    2859||settings and global_settings||?||not reviewed||
    2960||utils/_decimal.py||lots, including code||not reviewed||
    30 
    31 '''THE FOLLOWING IS WORK IN PROGRESS.'''
    32 
    33 === Settings ===
    34 
    35 FIXME: not reviewed. Replacing the `global_settings` with `settings` -- probably no major issues.
    36 
    37 === utils/_decimal.py ===
    38 
    39 FIXME: not reviewed. Lot's of globals, global code as well.
     61||django/contrib/sites/models.py||SITE_CACHE||minor, one db hit intended, more than one possible||
    4062
    4163=== django/contrib/sites/models.py ===
Back to Top