What are loops? relative to python

im using fantastic eric4 ide to encode python, he got a tool created in the so-called “cyclope” that seems to be looking for loops. After starting it gives me a bunch of big bold red letters announcing that there is in my code many cycles. The problem is that the output is almost not amenable to analysis, and it is not clear what a cycle is after reading its output. ive browsed the web for hours and couldn't find as much as a blog. when cycles accumulate to a certain point, the profiler and debugger stop working: (.

The question is what are loops, as I know, when I do a loop, how can I avoid loops in python. thanks.

+4
source share
2 answers

A cycle (or “link cycle”) is two or more objects that reference each other, for example:

alist = [] anoth = [alist] alist.append(anoth) 

or

 class Child(object): pass class Parent(object): pass c = Child() p = Parent() c.parent = p p.child = c 

Of course, these are very simple examples with two-part cycles; real life examples are often longer and more complex. There is no magic bullet telling you that you just made a cycle - you just need to keep track of it. The gc module (whose specific task is to collect invalid garbage collection cycles) can help you diagnose existing cycles (when you set the appropriate debug flags). The weakref module can help you avoid creating loops when you need it (for example, a child and a parent, to know about each other without creating a reference loop (make only one of two reciprocal links in a weak ref or proxy, or use convenient containers with a weak dictionary supplied by the module).

+4
source

All Cyclops tell you if there are objects in your object that refer to themselves through a chain of other objects. This was a problem in python because the garbage collector did not handle these objects correctly. Since then, this problem has been fixed for the most part.

Bottom line: if you do not observe a memory leak, you do not need to worry about Cyclops exiting in most cases.

+1
source

All Articles