def use_resources(num_threads, num_gb):
 def _use_gb_ram(num_gb):
  u'\n        Function to consume GB of memory\n        '
  import sys
  bsize = (sys.getsizeof(u'  ') - sys.getsizeof(u' '))
  boffset = sys.getsizeof(u'')
  num_bytes = int((num_gb * (1024 ** 3)))
  gb_str = (u' ' * ((num_bytes - boffset) // bsize))
  assert (sys.getsizeof(gb_str) == num_bytes)
  ctr = 0
  while (ctr < 30000000.0):
   ctr += 1
  del ctr
  del gb_str
 from multiprocessing import Process
 from threading import Thread
 num_gb = float(num_gb)
 thread_list = []
 for idx in range(num_threads):
  thread = Thread(target=_use_gb_ram, args=((num_gb / num_threads),), name=str(idx))
  thread_list.append(thread)
 print((u'Using %.3f GB of memory over %d sub-threads...' % (num_gb, num_threads)))
 for (idx, thread) in enumerate(thread_list):
  thread.start()
 for thread in thread_list:
  thread.join()

def use_resources ( num_threads , num_gb ) : def _use_gb_ram ( num_gb ) : import sys bsize = ( sys . getsizeof ( u'  ' ) - sys . getsizeof ( u' ' ) ) boffset = sys . getsizeof ( u'' ) num_bytes = int ( ( num_gb * ( 1024 ** 3 ) ) ) gb_str = ( u' ' * ( ( num_bytes - boffset ) // bsize ) ) assert ( sys . getsizeof ( gb_str ) == num_bytes ) ctr = 0 while ( ctr < 30000000.0 ) : ctr += 1 del ctr del gb_str from multiprocessing import Process from threading import Thread num_gb = float ( num_gb ) thread_list = [ ] for idx in range ( num_threads ) : thread = Thread ( target = _use_gb_ram , args = ( ( num_gb / num_threads ) , ) , name = str ( idx ) ) thread_list . append ( thread ) print ( ( u'Using %.3f GB of memory over %d sub-threads...' % ( num_gb , num_threads ) ) ) for ( idx , thread ) in enumerate ( thread_list ) : thread . start ( ) for thread in thread_list : thread . join ( )
function to execute multiple use_gb_ram functions in parallel .