Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StopIteration raised every time #243

Open
vlordier opened this issue Aug 9, 2018 · 8 comments · May be fixed by #251
Open

StopIteration raised every time #243

vlordier opened this issue Aug 9, 2018 · 8 comments · May be fixed by #251

Comments

@vlordier
Copy link

vlordier commented Aug 9, 2018

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
@paulsantolla
Copy link

paulsantolla commented Oct 9, 2018

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
Copy link

paulsantolla commented Oct 9, 2018

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

@agodbehere
Copy link

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.

fabianhoward added a commit to Krzana/pattern that referenced this issue Nov 21, 2018
fabianhoward added a commit to Krzana/pattern that referenced this issue Nov 21, 2018
@fabianhoward fabianhoward linked a pull request Nov 21, 2018 that will close this issue
@Raphencoder
Copy link

Raphencoder commented Feb 25, 2019

Same here on python 3.7, any update planned?

@Raysmond
Copy link

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.

@magnusja
Copy link

This is incredibly annoying when parallelizing with joblib ...

@Pikamander2
Copy link

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.

@nershman
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants