garbage-collection

Why garbage collection act weird this in Jupyter Notebook?

Why garbage collection act weird this in Jupyter Notebook? Question: why second loop don’t print any thing?! z_rng = zip(range(10), range(10)) # this loop is run and print for i,j in z_rng: print(i,j) # this loop is not run and don’t print anything for l, k in z_rng: print(l, k) Or when print as list …

Total answers: 1

timeit and its default_timer completely disagree

timeit and its default_timer completely disagree Question: I benchmarked these two functions (they unzip pairs back into source lists, came from here): n = 10**7 a = list(range(n)) b = list(range(n)) pairs = list(zip(a, b)) def f1(a, b, pairs): a[:], b[:] = zip(*pairs) def f2(a, b, pairs): for i, (a[i], b[i]) in enumerate(pairs): pass Results …

Total answers: 1

How to fully delete a turtle

How to fully delete a turtle Question: I made a small tkinter game that uses turtle for graphics. It’s a simulation of the Triangle Peg Game from Cracker Barrel that is able to tell the player the next best move to make at any point in the game, among other features. Pegs are just instances …

Total answers: 4

PyQt – parent for widgets – necessary?

PyQt – parent for widgets – necessary? Question: I tried creating GUI with a few widgets, all of them without secifying a parent. It worked fine. Is this Ok, or there is reason to specify the parent? Thanks! Asked By: Israel Unterman || Source Answers: In general, it’s better to specify a parent wherever possible, …

Total answers: 1

Why should you manually run a garbage collection in python?

Why should you manually run a garbage collection in python? Question: I have occasionally come across code that manually calls gc.collect(), but it’s unclear why. For what reasons, if any, would it be advantageous to manually run a garbage collection, rather than let Python handle it automatically? Asked By: Brendan Abel || Source Answers: In …

Total answers: 2

Is there a need to delete a large variable in python immediately after its use?

Is there a need to delete a large variable in python immediately after its use? Question: If I create a list that’s 1 GB, print it to screen, then delete it, would it also be deleted from memory? Would this deletion essentially be like deallocating memory such as free() in C. If a variable is …

Total answers: 2

What does self = None do?

What does self = None do? Question: I’m reading the source code of the incoming asyncio package. Note that at the end of the method, there is a self = None statement. What does it do? def _run(self): try: self._callback(*self._args) except Exception as exc: msg = ‘Exception in callback {}{!r}’.format(self._callback, self._args) self._loop.call_exception_handler({ ‘message’: msg, ‘exception’: …

Total answers: 2

Why disable the garbage collector?

Why disable the garbage collector? Question: Pythons gc.disable disables automatic garbage collection. As I understand it, that would have quite some side-effects. Why would anyone want to disable automatic garbage collection, and how could one effectively manage memory without it? Asked By: gerrit || Source Answers: One use for disabling the garbage collector is to …

Total answers: 4

Find all references to an object in python

Find all references to an object in python Question: What is a good way to find all of the references to an object in python? The reason I ask is that it looks like we have a “memory leak”. We are uploading image files to the server from a web browser. Each time we do …

Total answers: 2