Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import psutil
- import random
- import resource
- import sys
- def test_whirl_string_memory_limit(whirler, bfs):
- size = sys.getsizeof(bfs)
- process = psutil.Process(os.getpid())
- usage = process.memory_info().rss
- soft, hard = resource.getrlimit(resource.RLIMIT_AS)
- resource.setrlimit(resource.RLIMIT_AS, (usage + size/2, hard))
- try:
- print(whirler(bfs))
- except OSError:
- print('try harder')
- def working_answer(bfs):
- """
- will paste some good code
- :param bfs:
- :return:
- """
- pass
- def not_working_answer(bfs):
- """
- should fail cuz memory limit
- :param bfs:
- :return:
- """
- res = ''
- for char in sorted(bfs):
- res += char
- return res
- if __name__ == '__main__':
- snicks_string = str(random.randint(100000000000000000000000000000000, 1000000000000000000000000000000000))
- print(snicks_string)
- test_whirl_string_memory_limit(not_working_answer, snicks_string)
Advertisement
Add Comment
Please, Sign In to add comment