No, this list is not a linked list.
Since mu original code is rather huge, I am presenting
the relevant snippet.
queue=[]
def genpassenger(num,destination,queue=queue):
for i in range(num):
newpass=passenger(destination)
queue.append(newpass)
newpass.start()
class passenger(threading.Thread):
def __init__
<snip>
def run:
#do something
delete itself
genpassengers is called interactively by the user
.Also there can be multiple instances of genpassengers
running at the same time.
Now my questions are:
1) Generically , how do i accomplish the delete itself
part
2) If i used a linked list, does automatic memory
handling by python entail that delete itself is
automatically accomplished once i have readjusted the
pointers, since no further reference to the instance
remains.(Of course, if it doesnt i can get a reference
in the external code(in case of a doubly linked
list)).
3) How about making a destructor function (on lines
of c++) and deleting all the variables of the
class.Does it free all my memory or is there still
some memory being used, though the instance has no
variables stored.
Shitiz
--- Kent Johnson <[EMAIL PROTECTED]> wrote:
> Shitiz Bansal wrote:
> > Hi,
> > How do i delete a class instance in a function
> running
> > within itself?
> > All the instances of the class are stored in a
> list,
> > and they need to be deleted after executing their
> > function.
> > However since the list is dynamic, there is no way
> to
> > know the exact position of the instance within the
> > list.
>
> You have to do this from the caller, in code that
> has access to the list. There is no general way
> for an object to find out how it is being referenced
> in external code. Can you show some of the code
> that creates and uses the list? Does the code that
> calls the class know where the class is in the list?
>
> Is this the linked list you asked about before that
> is modified from two threads?
>
> >
> > I tried del self to no avail.
>
> del self just removes the link between the name
> 'self' and the object it references.
>
> Kent
>
> _______________________________________________
> Tutor maillist - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor