Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in debugging #3174

Open
akbzam opened this issue Apr 27, 2024 · 1 comment
Open

error in debugging #3174

akbzam opened this issue Apr 27, 2024 · 1 comment
Labels
Milestone

Comments

@akbzam
Copy link

akbzam commented Apr 27, 2024

hi
in below code, i set breakpoint in line 49.
in ordinary running , the code is ok, but in debugging the code stoped and not response at all.
the code:

#from:https://blog.faradars.org/reduce-memory-usage-and-make-your-python-code-faster-using-generators/
'''generators'''

def generate_numbers():
    n = 0
    while n < 3:
        yield n
        n += 1

numbers = generate_numbers()
print(type(numbers))   #<class 'generator'>

next_number = generate_numbers()
next(next_number)     #0
next(next_number)     #1
next(next_number)     #2
#next(next_number)     # this line causes StopIteration error, because generator is exhausted.

'''
problem to be solved: in a large list( for example 100,000,000) calculate the cube of even numbers.
'''

import memory_profiler
import time

#ordianary method:
def check_even_list(numbers):
    even = []
    for num in numbers:
        if num % 2 == 0: 
            even.append(num*num)
            
    return even

#using generator
def check_even_gene(numbers):
    for num in numbers:
        if num % 2 == 0:
            yield num * num 
    

    
if __name__ == '__main__':
    m1 = memory_profiler.memory_usage()
    t1 = time.time()
    cubes = check_even_list(range(100000000))  #ordinary method with using list
    t2 = time.time()
    m2 = memory_profiler.memory_usage()       # breakpoint set here in this line
    time_diff = t2 - t1
    mem_diff = m2[0] - m1[0]
    print(f"It took {time_diff} Secs and {mem_diff} Mb to execute this method with using list.")
    
    
    m3 = memory_profiler.memory_usage()
    t3 = time.time()
    cubes = check_even_gene(range(100000000))
    t4 = time.time()
    m4 = memory_profiler.memory_usage()
    time_diff = t4 - t3
    mem_diff = m4[0] - m3[0]
    print(f"It took {time_diff} Secs and {mem_diff} Mb to execute this method with using generator.")

without dubugging and in normaly run , the code is runed in 22 second, but as i said in dubbuging( with breakpoint in line 49)the code goes in halt state and hangs.

@aivarannamaa
Copy link
Member

Thanks! I'll try to reproduce and fix this later.

@aivarannamaa aivarannamaa added this to the 5.0.x milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants