pattern icon indicating copy to clipboard operation
pattern copied to clipboard

StopIteration raised every time

Open vlordier opened this issue 7 years ago • 8 comments

In /text/init.py StopIteration gets raised every time

def _read(path, encoding="utf-8", comment=";;;"):
    """ Returns an iterator over the lines in the file at the given path,
        strippping comments and decoding each line to Unicode.
    """
    if path:
        if isinstance(path, str) and os.path.exists(path):
            # From file path.
            f = open(path, "r", encoding="utf-8")
        elif isinstance(path, str):
            # From string.
            f = path.splitlines()
        else:
            # From file or buffer.
            f = path
        for i, line in enumerate(f):
            line = line.strip(BOM_UTF8) if i == 0 and isinstance(line, str) else line
            line = line.strip()
            line = decode_utf8(line, encoding)
            if not line or (comment and line.startswith(comment)):
                continue
            yield line
    raise StopIteration

vlordier avatar Aug 09 '18 17:08 vlordier

Experiencing the same issue. Works the second+ time it is used for some reason. screen shot 2018-10-09 at 3 20 24 pm

paulsantolla avatar Oct 09 '18 19:10 paulsantolla

Soo.. since it only fails the first time... One can throw a hack into files to get it to work. Here's a quick & dirty fix until this is resolved:

screen shot 2018-10-09 at 3 56 52 pm

paulsantolla avatar Oct 09 '18 19:10 paulsantolla

This issue is likely due to PEP-479 (https://www.python.org/dev/peps/pep-0479/)

This introduced a breaking change in the handling of "StopIteration" in generators that was activated by default in Python 3.7. In Python3.6, you would have seen a warning about the upcoming deprecation.

Someone should refer to PEP-479, in particular this section (https://www.python.org/dev/peps/pep-0479/#id38) to refactor this code. At first glance, I would bet that replacing raise StopIteration with return will do the trick.

agodbehere avatar Oct 16 '18 01:10 agodbehere

Same here on python 3.7, any update planned?

Raphencoder avatar Feb 25 '19 10:02 Raphencoder

Try this,

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 3.6.8

It didn't work with Python 3.7. Python 3.6 works for me.

Raysmond avatar Apr 28 '19 03:04 Raysmond

This is incredibly annoying when parallelizing with joblib ...

magnusja avatar Jun 28 '19 09:06 magnusja

Here's an easy workaround:

def pattern_stopiteration_workaround():
    try:
        print(lexeme('gave'))
    except:
        pass

def main():
    pattern_stopiteration_workaround()
    #Add your other code here

Basically, the pattern code will fail the first time you run it, so you first need to run it once and catch the Exception it throws.

It's worked well enough for my own scripts, but I don't know if it fixes every possible issue.

Ideally though, somebody should fork the clips/pattern project since it's no longer maintained.

Pikamander2 avatar May 15 '21 08:05 Pikamander2

Here's an easy workaround:

def pattern_stopiteration_workaround():
    try:
        print(lexeme('gave'))
    except:
        pass

def main():
    pattern_stopiteration_workaround()
    #Add your other code here

Basically, the pattern code will fail the first time you run it, so you first need to run it once and catch the Exception it throws.

It's worked well enough for my own scripts, but I don't know if it fixes every possible issue.

Ideally though, somebody should fork the clips/pattern project since it's no longer maintained.

If you use this method you should do 'except RuntimeError', in case you get any other error instead.

nershman avatar Jul 10 '21 14:07 nershman