Changeset 6230 for anuga_core/source/anuga/caching/caching.py
- Timestamp:
- Jan 22, 2009, 1:24:06 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/caching/caching.py
r6222 r6230 86 86 'bin': 1, # Use binary format (more efficient) 87 87 'compression': 1, # Use zlib compression 88 'bytecode': 0, # Recompute if bytecode has changed88 'bytecode': 1, # Recompute if bytecode has changed 89 89 'expire': 0 # Automatically remove files that have been accessed 90 90 # least recently … … 162 162 If the function definition changes after a result has been cached it will be 163 163 detected by examining the functions bytecode (co_code, co_consts, 164 func_def ualts, co_argcount) and it will be recomputed.164 func_defaults, co_argcount) and it will be recomputed. 165 165 166 166 LIMITATIONS: … … 1382 1382 val = myhash(I, ids) 1383 1383 elif type(T) == num.ArrayType: 1384 T = num.array(T) # Ensure contiguous1384 T = num.array(T) # Ensure array is contiguous 1385 1385 1386 1386 # Use mean value for efficiency 1387 1387 val = hash(num.average(T.flat)) 1388 1388 elif type(T) == InstanceType: 1389 # Use the attribute values 1389 1390 val = myhash(T.__dict__, ids) 1390 1391 else: … … 1547 1548 1548 1549 if type(func) == types.FunctionType: 1549 bytecode = func.func_code.co_code 1550 consts = func.func_code.co_consts 1551 argcount = func.func_code.co_argcount 1552 defaults = func.func_defaults 1550 return get_func_code_details(func) 1553 1551 elif type(func) == types.MethodType: 1554 bytecode = func.im_func.func_code.co_code 1555 consts = func.im_func.func_code.co_consts 1556 argcount = func.im_func.func_code.co_argcount 1557 defaults = func.im_func.func_defaults 1552 return get_func_code_details(func.im_func) 1553 elif type(func) == types.InstanceType: 1554 if callable(func): 1555 # Get bytecode from __call__ method 1556 bytecode = get_func_code_details(func.__call__.im_func) 1557 1558 # Add hash value of object to detect attribute changes 1559 return bytecode + (myhash(func),) 1560 else: 1561 msg = 'Instance %s was passed into caching in the role of a function ' % str(func) 1562 msg = ' but it was not callable.' 1563 raise Exception, msg 1564 elif type(func) in [types.BuiltinFunctionType, types.BuiltinMethodType]: 1565 # Built-in functions are assumed not to change 1566 return None, 0, 0, 0 1567 elif type(func) == types.ClassType: 1568 # Get bytecode from __init__ method 1569 bytecode = get_func_code_details(func.__init__.im_func) 1570 return bytecode 1558 1571 else: 1559 #raise Exception #Test only 1560 bytecode = None #Built-in functions are assumed not to change 1561 consts = 0 1562 argcount = 0 1563 defaults = 0 1564 1565 return (bytecode, consts, argcount, defaults) 1572 msg = 'Unknown function type: %s' % type(func) 1573 raise Exception, msg 1574 1575 1576 1577 1578 def get_func_code_details(func): 1579 """Extract co_code, co_consts, co_argcount, func_defaults 1580 """ 1581 1582 bytecode = func.func_code.co_code 1583 consts = func.func_code.co_consts 1584 argcount = func.func_code.co_argcount 1585 defaults = func.func_defaults 1586 1587 return bytecode, consts, argcount, defaults 1566 1588 1567 1589 # -----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.