Python Forum
Code starts slowing down? MemoryError
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code starts slowing down? MemoryError
#2
Problem solved!

For those who get the same error, here is the answer:
the problem in the line that causes this error is the transformation from a generator (a piece of code that yields one result at a time until it finishes running) that is very memory-efficient, to a list by using [] around
functools.reduce(operator.add, p) for p in itertools.product(chars, repeat=n)
.
by converting it into a list you make the generator output all its values into a list, which cannot contain more than 536,870,912 items on 32bit machines. when the list gets bigger than that you get the memory error.

solution: remove the []
Reply


Messages In This Thread
RE: Code starts slowing down? MemoryError - by AshkanDev - May-19-2020, 11:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  MemoryError in pywinauto.findwindows.find_windows – Need Help! ktw3857 1 352 Apr-18-2024, 04:28 PM
Last Post: itegumo
  Problem with my code slowing down and crashing SuchUmami 1 524 Jul-21-2023, 10:09 AM
Last Post: Gribouillis
  Move column to the right if it starts with a letter mfernandes 0 691 Oct-25-2022, 11:22 AM
Last Post: mfernandes
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,842 Feb-18-2022, 01:29 PM
Last Post: pstein
  Regex: a string does not starts and ends with the same character Melcu54 5 2,460 Jul-04-2021, 07:51 PM
Last Post: Melcu54
  Run a timer when a functions starts to see how long the function takes to complete Pedroski55 2 2,032 Apr-19-2020, 06:28 AM
Last Post: Pedroski55
  Getting MemoryError frames.write(buffer) kunwarsingh 0 1,628 Feb-10-2020, 09:39 PM
Last Post: kunwarsingh
  sensor code that starts heater chano 3 3,164 Jun-05-2019, 10:54 AM
Last Post: michalmonday
  MemoryError AwaAgathe 0 1,749 Feb-26-2019, 02:57 AM
Last Post: AwaAgathe
  MemoryError mitmoot 5 3,861 Dec-07-2018, 04:53 PM
Last Post: mitmoot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020