Guest User

Untitled

a guest
Dec 24th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import os
  2. import psutil
  3. import random
  4. import resource
  5. import sys
  6.  
  7.  
  8. def test_whirl_string_memory_limit(whirler, bfs):
  9.     size = sys.getsizeof(bfs)
  10.     process = psutil.Process(os.getpid())
  11.     usage = process.memory_info().rss
  12.     soft, hard = resource.getrlimit(resource.RLIMIT_AS)
  13.     resource.setrlimit(resource.RLIMIT_AS, (usage + size/2, hard))
  14.  
  15.     try:
  16.         print(whirler(bfs))
  17.     except OSError:
  18.         print('try harder')
  19.  
  20.  
  21. def working_answer(bfs):
  22.     """
  23.    will paste some good code
  24.    :param bfs:
  25.    :return:
  26.    """
  27.     pass
  28.  
  29.  
  30. def not_working_answer(bfs):
  31.     """
  32.    should fail cuz memory limit
  33.    :param bfs:
  34.    :return:
  35.    """
  36.     res = ''
  37.     for char in sorted(bfs):
  38.         res += char
  39.  
  40.     return res
  41.  
  42.  
  43. if __name__ == '__main__':
  44.     snicks_string = str(random.randint(100000000000000000000000000000000, 1000000000000000000000000000000000))
  45.     print(snicks_string)
  46.     test_whirl_string_memory_limit(not_working_answer, snicks_string)
Advertisement
Add Comment
Please, Sign In to add comment