def limitedMemory(limit, func, *args, **kw):
 clearCaches()
 max_rss = getMemorySize()
 if (max_rss is not None):
  old_limit = getMemoryLimit()
  limit = (max_rss + limit)
  limited = setMemoryLimit(limit)
 else:
  limited = False
 try:
  return func(*args, **kw)
 finally:
  if limited:
   setMemoryLimit(old_limit)
  clearCaches()

def limitedMemory ( limit , func , * args , ** kw ) : clearCaches ( ) max_rss = getMemorySize ( ) if ( max_rss is not None ) : old_limit = getMemoryLimit ( ) limit = ( max_rss + limit ) limited = setMemoryLimit ( limit ) else : limited = False try : return func ( * args , ** kw ) finally : if limited : setMemoryLimit ( old_limit ) clearCaches ( )
limit memory grow when calling func: restrict memory grow to limit bytes .