Changes between Version 14 and Version 15 of DjangoSpecifications/Core/Threading
- Timestamp:
- Apr 14, 2008, 2:27:47 AM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DjangoSpecifications/Core/Threading
v14 v15 21 21 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). 22 22 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 27 Incomplete initialization errors can generally be avoided by using full 28 assignment instead of elementwise modification (that's how it is done in the 29 source mostly). That is, 30 31 '''BAD''' 32 {{{ 33 foo = [] 34 def bar(): 35 ... 36 if not foo: 37 for x in y: 38 foo.append(x) 39 }}} 40 41 '''BETTER''' 42 {{{ 43 foo = [] 44 def 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 23 54 The following modules' use of globals needs review. 24 55 … … 28 59 ||settings and global_settings||?||not reviewed|| 29 60 ||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|| 40 62 41 63 === django/contrib/sites/models.py ===