On Thu, 2 Mar 2023, at 22:33, Clayton Macleod wrote:

> I pared the script down so that the only things it was doing was connecting
> to iTunes to get the song library list and then doing a loop where it
> printed song.Name for random entries 1,000 times using "try" so it would
> continue if there was an error. This worked perfectly, so I was confused.

> I started adding commands back in one at a time until it finally started
> producing errors after a playlist.Tracks[0].Delete() command was executed.

I only have the sketchiest idea of what your code is doing, and know nothing
about iTunes' internal data-structures but I wonder ... when you delete an item
(from your playlist? - is that held only by your code or is it within iTunes??) 
whether that causes iTunes' lists of items to get rebuilt, so that pointers to 
them that you had are no longer valid?

I don't know if that makes sense.

If it's possible to extract a list of everything that iTunes knows about before 
a delete, and the same list afterwards, can you see if it changes more than
you expected?  I guess that might not help unless you can see, if eg data is
held on a linked list, whether the whole list changes or if an element is 
merely unlinked but the other items are still where they used to be.

> I can now reproduce the problem very easily. Only 1/20 trials ran without
> error once I reintroduced the delete command. 19/20 trials produced
> hundreds of errors in the 1,000 attempts in the loop.

That suggests to me that either all items on an original list before the one
you deleted might still be "in the same place" but maybe everything after 
it have moved.  Or something.


-- 
Jeremy Nicoll - my opinions are my own.
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to