Find the max id available in Python

-2

I have written a code to find the max free id in Python. However, when I try to print the max value, it returns Memory Error. Additionally, I cannot stay at the interpreter with python -i test.py as it will return a lot of Memory Error warnings and exit.

Here is the code I have written: (There are many Error Handlings as I want to skip the Memory Error)

wtf = lambda x:lambda t: x+t # To create the free local functions
a = [] # To store the functions

try:
 for _ in range(int("0xFFFFFFFF", 16)): # Maximum of id 0xFFFFFFFF
  try:
   a.append(wtf(_))
  except:
   break
except:
 pass

# Used to split the array to avoid the Memory Error
length = len(a)
n = 10000
every = int(length/n)
diff = length - n*every

ids = []
try:
 for i in range(n):
  try:
   abc = a[i*every:(i+1)*every-1]
  except:
   abc = a[i*every:(i+1)*every-1+diff]
  try:
   for _ in abc:
    try:
     ids.append(id(_))
    except:
     pass
  except:
   pass
except:
 pass

# Split the array to get the maxes
maxs = []
try:
 for i in range(n):
  try:
   abc = ids[i*every:(i+1)*every-1]
  except:
   abc = ids[i*every:(i+1)*every-1+diff]
  maxs.append(max(abc))
except:
 pass

print(hex(max(maxs))) # Should plus 3 as there are 3 variables totally defined before wtf functions

I have tried to split the arrays, but it didn't work. How could I do to get the result (i.e. max(ids))? It returns Memory Error now.

python
asked on Stack Overflow Jun 12, 2020 by ONLYA • edited Jun 12, 2020 by ONLYA

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0