RecursionError with cython compiled PySide2 code in Maya 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm getting this error when connecting a QWidget signal to a class method in Maya2022 (python 3):
`RecursionError: maximum recursion depth exceeded while calling a Python object`.
Has anyone at Autodesk (or elsewhere) encounter this issue?
Details below (let me know if you need more).
This only happens when the code is compiled with cython and setuptools (on Windows 10).
Using partial to wrap the method avoids the error, but this is not a good enough solution.
Here is a piece of code that can reproduce the issue (note: it needs to be compiled to see the error):
from PySide2.QtWidgets import *
import shiboken2
from maya import OpenMayaUI
from functools import partial
class TestMain(QMainWindow):
def __init__(self, *args, **kwargs):
super(TestMain, self).__init__(*args, **kwargs)
wid = QPushButton('push')
self.setCentralWidget(wid)
# using partial works well
# wid.clicked.connect(partial(self.push, None))
# without partial the error occurs
wid.clicked.connect(self.push)
def push(self, *args):
print(args)
print('pushed')
def launch():
ptr = OpenMayaUI.MQtUtil.mainWindow()
parent = shiboken2.wrapInstance(int(ptr), QWidget)
window_class = TestMain(parent=parent)
window_class.show()
And if it helps, here's my setup.py file used for compiling:
from setuptools import setup
from setuptools import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("simple_window", ["simple_window.py"])]
setup(
name= 'Simple Test Window',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules)
Compilation details:
- Windows 10
- Visual Studio 2019
- Using Maya 2022's mayapy.exe
- I used mayapy's pip to install setuptools, cython and build
- I'm setting up my environment in windows 10 this way:
set LIB=%LIB%;C:\Program Files\Autodesk\Maya2022\include\Python37\Python;C:\Program Files\Autodesk\Maya2022\lib
set INCLUDE=%INCLUDE%;C:\Program Files\Autodesk\Maya2022\include\Python37\Python- And finally running the compiler this way:
call "C:/Program Files (x86)/Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 && "C:\Program Files\Autodesk\Maya2022\bin\mayapy.exe" setup.py build
Here's a related stackoverflow question (with no definite solution):