How to Eat Memory using Python?

前端 未结 5 530
无人及你
无人及你 2021-01-31 16:10

Just for experiment, and Fun... I am trying to create an app that can \"Purposely\" consume RAM as much as we specify immediately. e.g. I want to consume 512 MB RAM, then the ap

5条回答
  •  时光说笑
    2021-01-31 17:04

    You can allocate a huge amount of ram by executing :

    while True:
        for i in range(0,100000000):
            Gig = 1024*1024*1024*2#A Gig multiplied by 2
            a = 787878788888888888888888888888 * (i * Gig)
            a = a * i
            print str(a)*2
    

    I found this code freezing my pc in 5 minutes
    Save it in a .pyw for background ram allocation
    If it doesn't freeze your pc try increasing the a's value
    To stop it quickly,Save this code in a .py file:

    #First we send signals
    os.system("TASKKILL /im pythonw.exe")
    os.system("TASKKILL /im python.exe") 
    print "Forcefull termination"
    #Now we forcefully terminate
    #pythonw.exe if running in idle or background
    os.system("TASKKILL /im python.exe /f")
    os.system("TASKKILL /im pythonw.exe /f")
    os.system("pause")
    

提交回复
热议问题