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

'return' with argument inside generator #353

Open
hellohornet opened this issue Jan 13, 2020 · 11 comments · May be fixed by #362
Open

'return' with argument inside generator #353

hellohornet opened this issue Jan 13, 2020 · 11 comments · May be fixed by #362

Comments

@hellohornet
Copy link

Whenever I run pyblish_qml.show() either from maya or python2 -m pyblish_qml --demo I successfully load the QML server, then am met with

File "P:\util\maya\Maya2020\experimental\lib\Python27\lib\runpy.py", line 162, in _run_module_as_main
Traceback (most recent call last):
SyntaxError: 'return' with argument inside generator
yield result
File "P:\util\maya\Maya2020\experimental\pyblish_qml\control.py", line 378
from . import util, compat, control, settings, ipc
File "P:\util\maya\Maya2020\experimental\pyblish_qml\app.py", line 15, in <module>
from . import app
File "P:\util\maya\Maya2020\experimental\pyblish_qml\__main__.py", line 6, in <module>
exec code in run_globals
File "P:\util\maya\Maya2020\experimental\lib\Python27\lib\runpy.py", line 72, in _run_code
"__main__", fname, loader, pkg_name)

It is my understanding that this is behavior that works in python3 but not 2.7, which is a necessity for Maya. Do I need to check out a different branch for 2.7 support ?

@mottosso
Copy link
Member

Thanks for reporting this @hellohornet. Can you confirm whether this work in Maya less than 2020 (experimental)? I suspect there's some issue there, as I know they are also in the process of upgrading their Python distribution. It should work just find in both 2 and 3, and has been for years.

@kaedehao
Copy link

kaedehao commented Feb 6, 2020

I've seen same error when using python2.7 -m pyblish_qml --demo (tested in both CentOS7 &
Ubuntu 18.04.3 LTS)
Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/lib/python2.7/site-packages/pyblish_qml/main.py", line 6, in
from . import app
File "/usr/lib/python2.7/site-packages/pyblish_qml/app.py", line 15, in
from . import util, compat, control, settings, ipc
File "/usr/lib/python2.7/site-packages/pyblish_qml/control.py", line 378
yield result
SyntaxError: 'return' with argument inside generator

PyQt5 built manually and tested OK

In Maya2019.2 (CentOS 7):
pyblish_qml.show() returns "no module named site"

@buddly27
Copy link

I've got the same error by running the demo with Python 2.7.15 on macOS and CentOS 7. Works great with Python 3 but it doesn't seem to be working in Nuke 10.5/11/12 either...

> python -m pyblish_qml --demo
Traceback (most recent call last):
  File "/mill3d/server/apps/PYTHON/el7-x86-64/python-2.7.15/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/mill3d/server/apps/PYTHON/el7-x86-64/python-2.7.15/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/mill3d/users/jeremyr/dev/pyblish-qml/pyblish_qml/__main__.py", line 6, in <module>
    from . import app
  File "pyblish_qml/app.py", line 12, in <module>
    from . import util, compat, control, settings, ipc
  File "pyblish_qml/control.py", line 380
    yield result
SyntaxError: 'return' with argument inside generator

@davidlatwe
Copy link
Collaborator

Were using environment variable PYBLISH_QML_PYTHON_EXECUTABLE for using newer version of Python is an option to you ?

@davidlatwe
Copy link
Collaborator

This issue was because of PRs #350 and #349, for fixing #333 which was using Python 3.7, where PEP 479 has been enabled.

If you guys could change to use newer version of Python would be great, but if not, should we mantain a branch for Python 27 ?

@davidlatwe
Copy link
Collaborator

Was looking at the code, it seems that pyblish-qml was actually not relying on generator to stop by itself, but check on the type of the result instead, see this line.

So replacing those return statement inside generator with yield may solved this issue.

Has a quick test with Python 3.7 and it's working just fine, but I cannot test against Python 2.7 since that would require to build PyQt5>=5.7.1 manually, because the latest python-qt5 was only 5.3.

Anyone could help verifying this on Python 2.7 ? 👇

replacing those return statement inside generator with yield may solved this issue

@mottosso
Copy link
Member

This issue was because of PRs ... where PEP 479 has been enabled.

Aaah, yes of course.

Ok, so workarounds:

  1. Use Python 3, it's about time anyway
  2. Downgrade Pyblish QML to before that PR
  3. Apply the fix @davidlatwe mention

So replacing those return statement inside generator with yield may solved this issue.

The return, much like raise is supposed to stop the iterator. A yield would carry on with the next line. Worst case, we'll need to refactor it into a if this: yield else do_nothing()-type thing. If we can't stop execution.

I can't figure out how we're supposed to do it. :S We can't return, and we can't raise.

@BigRoy
Copy link
Member

BigRoy commented Feb 10, 2020

Not sure I'm getting this discussion, but to stop an iterator means to just do return right? As long as you don't pass any arguments:

def custom_iterator(value):

    if value == "a":
        yield 1
        yield 2
        yield 3
        return

    yield 0

for x in custom_iterator("a"):
    print(x)
# 1
# 2
# 3

for x in custom_iterator("b"):
    print(x)
# 0

SyntaxError: 'return' with argument inside generator

This just means you're returning with an argument, which is invalid inside an iterator. To yield one last value before you return the way to do it is:

yield last_value
return

Or to raise an error without returning/yielding if all you want is just to raise an error.

Or am I stating something obvious and am I missing the point?

@davidlatwe
Copy link
Collaborator

This just means you're returning with an argument, which is invalid inside an iterator. To yield one last value before you return the way to do it is:

yield last_value
return

Yeah, that could work in both Python 2.7 and Python 3.7.

Anyway, the minimum fix (less code) for this issue was to replace those return ... with yield ..., because we actually don't need that iterator to stop by itself (return or raise any error), it already will be stopped from the outside here.

And it was not only stopping the iterator, but also prompting the message of why it stopped from the iterator, like due to the failed validation or stopped by user.

@buddly27 buddly27 linked a pull request Mar 8, 2020 that will close this issue
@satoy11
Copy link

satoy11 commented Dec 26, 2020

Hi,

I wanted to use Pyblish with a combination of Windows 10 and Maya2018, but there has error.

> C:\Python27\python.exe  -m pip install python-qt5
> set PYBLISH_QML_PYTHON_EXECUTABLE=C:\Python27\python.exe
> set PYBLISH_QML_PYQT5=C:\Python27\Lib\site-packages\PyQt5
> C:\Python27\python.exe  -m pip install pyblish-qml
> C:\Python27\python.exe  -m pip install pyblish-maya
> C:\Python27\python.exe -m pyblish_qml --demo
Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\lib\site-packages\pyblish_qml\__main__.py", line 6, in <module>
    from . import app
  File "C:\Python27\lib\site-packages\pyblish_qml\app.py", line 12, in <module>
    from . import util, compat, control, settings, ipc
  File "C:\Python27\lib\site-packages\pyblish_qml\control.py", line 380
    yield result
SyntaxError: 'return' with argument inside generator

Then, I found this article about a similar problem.
and I replaced the return in control.py with yield as specified in this link, but the result was the same.

if isinstance(result, StopIteration):

Next, I replaced all returns in control.py with yield.
This time, the Window appeared for a moment, but quickly disappeared and there was another error.

Starting pyblish-qml server..
Using Python @ 'C:\Python27\python.exe'
Using PyQt5 @ 'C:\Python27\Lib\site-packages\PyQt5'
Targets: default
Starting pyblish-qml
Done, don't forget to call `show()`
Settings:
HeartbeatInterval = 60
WindowTitle = Pyblish
WindowPosition = [100, 100]
WindowSize = [430, 600]
ContextLabel = Context
HiddenSections = [u'Collect']
Awaited statemachine for 0.00 ms
TypeError: unable to convert a Python 'generator' object to a C++ 'bool' instance

Could you give me some advice about this?

@mottosso
Copy link
Member

My advice would be #353 (comment)

NOTE The version of Python you use with QML is independent of the version Maya uses.

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

Successfully merging a pull request may close this issue.

7 participants