classification
Title: random.uniform() hangs will eating up all available RAM
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Christian.Kleineidam, jack__d, rhettinger, steven.daprano
Priority: normal Keywords:

Created on 2021-06-14 18:47 by Christian.Kleineidam, last changed 2021-06-15 00:17 by steven.daprano. This issue is now closed.

Files
File name Uploaded Description Edit
obfuscated.py Christian.Kleineidam, 2021-06-14 18:47 Test file that demonstrates how the program hangs in random.uniform(0, 1)
Messages (4)
msg395836 - (view) Author: Christian Kleineidam (Christian.Kleineidam) Date: 2021-06-14 18:47
I'm writing a model that needs a lot of random numbers. The model counts up to "Year:640: Count:1339" (taking around two minutes) and then hangs on random.uniform(0, 1). While it hangs, the amount of RAM python takes grows till it eats up all available RAM with RAM usage growing by around 100 MB per second.

I'm running Windows 10 and the error appears in both Python 3.8.8 as well as in 3.9.5. I'm attaching a file that reproduces the error. 

File "C:\Users\Christian\folder\obfuscated.py", line 427, in <module>
    population = population.next()

  File "C:\Users\Christian\folder\obfuscated.py", line 385, in next
    return Class4(self.nextClass4)

  File "C:\Users\Christian\folder\obfuscated.py", line 280, in __init__
    var42.var30()

  File "C:\Users\Christian\folder\obfuscated.py", line 177, in var30
    var22.var30(self.var17,self.var18,self.var21)

  File "C:\Users\Christian\folder\obfuscated.py", line 100, in var30
    self.barClass1s.append(var23.child())

  File "C:\Users\Christian\folder\obfuscated.py", line 29, in child
    if var6>random.uniform(0, 1):

  File "C:\Progs\anaconda3\lib\random.py", line 417, in uniform
    return a + (b-a) * self.random()
msg395842 - (view) Author: Jack DeVries (jack__d) * Date: 2021-06-14 19:41
This doesn't look like a bug. It's hard to disentangle what your code is doing, exactly, but it's most likely that between all your nested loops and classes initializing each other, there is an exponential or greater growth in time complexity happening. As your input values grow, the program slows down at an exponential rate until it appears to just "hang".

The RAM is growing because the program hasn't really stopped running, it's just dutifully chugging along and filling up more and more memory, and if you waited long enough the program would either crash having run out of memory or maybe the program would complete in a very, very long time.

I hope I'm not missing something; feel free to let me know, or share a more minimal example to reproduce the issue.
msg395850 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-06-14 21:13
I concur with Jack. There is no evidence of a bug in Python itself and it is not reasonable to ask us the study and debug your obfuscated code.

I just ran random.uniform() in a tight loop for several minutes and observed no deleterious effects.  Am marking this as closed as not being a bug.
msg395854 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-06-15 00:17
Hi Christian,

For future reference, here are some good guidelines for submitting bug reports and asking for help to debug your code:

https://stackoverflow.com/help/minimal-reproducible-example

http://www.sscce.org/
History
Date User Action Args
2021-06-15 00:17:39steven.dapranosetnosy: + steven.daprano
messages: + msg395854
2021-06-14 21:16:11rhettingersetstatus: open -> closed
stage: resolved
2021-06-14 21:13:24rhettingersetnosy: + rhettinger
messages: + msg395850

assignee: rhettinger
resolution: not a bug
2021-06-14 19:41:38jack__dsetnosy: + jack__d
messages: + msg395842
2021-06-14 18:47:03Christian.Kleineidamcreate