rsgalloway / pyseq

Compressed sequence string module for Python
https://pyseq.rsgalloway.com/
Other
123 stars 36 forks source link

While loop issues get_sequences/iget_sequences #67

Closed lasselauch closed 2 years ago

lasselauch commented 2 years ago

Made an interesting discovery today: While searching a folder with the following filenames, pyseq stops to respond (!) and hangs itself.

pyseq_while_loop_error

My guess it's due to the nature of the while loop within the get_sequences and iget_sequences functions...

I was able to reproduce this issue with empty files, so here's a list of the filenames for further testing:

['gettyimages-1364769281-2048x2048.jpg', 'gettyimages-530573048-2048x2048.jpg', 'gettyimages-1127718214-2048x2048.jpg', 'gettyimages-470543560-2048x2048.jpg', 'gettyimages-155374807-2048x2048.jpg', 'gettyimages-1182189546-2048x2048.jpg', 'gettyimages-157742535-2048x2048.jpg']

Cheers, Lasse

rsgalloway commented 2 years ago

Interesting, thanks for the report. I'm able to reproduce this issue using lss as well.

Don't think it's a problem with the while loops. Technically, the names of these files make them a sequence as far as pyseq is concerned. Looks like it finds two of them:

>>> seqs = get_sequences(['gettyimages-1364769281-2048x2048.jpg', 'gettyimages-530573048-2048x2048.jpg', 'gettyimages-1127718214-2048x2048.jpg', 'gettyimages-470543560-2048x2048.jpg', 'gettyimages-155374807-2048x2048.jpg', 'gettyimages-1182189546-2048x2048.jpg', 'gettyimages-157742535-2048x2048.jpg'])
>>> len(seqs)
2

The problem seems to be the sequences sizes:

>>> seqs[0].frames()
[1127718214, 1182189546, 1364769281]

and when formatting these sequences it's trying to calculate the missing frames on line 363 which is many (commenting out that line seems to make it work again).

>>> seqs[0].format()
'   3 gettyimages-%d-2048x2048.jpg [1127718214, 1182189546, 1364769281]'

So it seems like the solution here might be to find a smarter way to calculate missing frames in _get_missing (edit: and/or calculating this on demand).

rsgalloway commented 2 years ago

@lasselauch FYI I've got a branch with a potential fix if you want to give it a try:

https://github.com/rsgalloway/pyseq/tree/issue-67

lasselauch commented 2 years ago

@rsgalloway Thanks, for the quick fix, that works great indeed!!! 🚀

rsgalloway commented 2 years ago

Great, thanks for testing. I'll get this merged and deployed to pypi shortly.