How to use pyblish with maya in standalone/batch mode

We have a heavy scene that we don’t necessarily want to open with graphical maya.
I wonder if it’s possibly use pyblish in maya with standalone/batch mode?
I’ve been able to register the plugins and when i try to show pyblish lite with no parent i can see that it tries to start but stops after printing:
Installed opensans\OpenSans-Regular.ttf
Installed opensans\OpenSans-Semibold.ttf
Installed fontawesome\fontawesome-webfont.ttf
Installed translator


PInging @BigRoy since he recently looked into maya standalone publishing on Deadline.

Thanks for pinging me! :wink:

I definitely looked into this recently, however I never tried to trigger a Pyblish interface in that standalone process. Also I never really used Pyblish-lite either, but run Pyblish-QML.

Anyway, you can test whether the pyblish functionality works in the standalone maya mode by running:

import pyblish.util
context = pyblish.util.publish()

Of course you can read out the returned context for errors/printed data and alike to check whether it succeeded.

If that all works, then we know your pyblish plug-ins are set and the maya functionality works too and we’ve found that it is a problem with Pyblish-lite. I believe Pyblish-lite will try to install itself into the host using the local Qt library found, which will be Maya’s Qt which I’m not sure will run correctly when in standalone mode. It should be able to though, just not sure.

Anyway, so I quickly tried Pyblish QML through mayapy.exe and found two issues:

  1. Whenever you run prior to maya.standalone.initialize() then you will get the following error:
>>> import pyblish_qml
Setting up Pyblish QML in Maya
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "P:\pipeline\2.1_dev\git\avalon-setup\git\pyblish-qml\pyblish_qml\", line 16, in show
    return, targets, modal, auto_publish, auto_validate)
  File "P:\pipeline\2.1_dev\git\avalon-setup\git\pyblish-qml\pyblish_qml\", line 97, in show
  File "P:\pipeline\2.1_dev\git\avalon-setup\git\pyblish-qml\pyblish_qml\", line 68, in install
  File "P:\pipeline\2.1_dev\git\avalon-setup\git\pyblish-qml\pyblish_qml\", line 242, in install_host
  File "P:\pipeline\2.1_dev\git\avalon-setup\git\pyblish-qml\pyblish_qml\", line 526, in _install_maya
    if cmds.about(version=True) == "2018":
AttributeError: 'module' object has no attribute 'about'

As such the error originates from this line since Maya has not been initialized yet and does not have the functions available in maya.cmds, as such maya.cmds.about does not exist yet.

This is resolved by first running:

import maya.standalone

Which you’ll likely need to do before you can really run any decent Maya commands anyway, as such to also have your pyblish plug-ins run correctly.

  1. Qt runs into a Dead lock when executing in the main thread of mayapy.exe, see:
>>> import pyblish_qml
Setting up Pyblish QML in Maya
Setting up Pyblish QML in Maya
Installing.. : INFO : Headless host
Using Python @ 'P:/pipeline/2.1_dev/bin/windows/python36\python.exe'
Using PyQt5 @ 'None'
Targets: default, local : INFO : Success. QML server available as pyblish_qml.api.current_server()
<pyblish_qml.ipc.server.Server object at 0x0000025E2476CD68>
>>> Starting pyblish-qml
Done, don't forget to call `show()`
Entering state: "hidden"
Entering state: "ready"
Entering state: "clean"
Entering state: "alive"
WindowPosition = [100, 100]
WindowSize = [430, 600]
HiddenSections = ['Collect']
HeartbeatInterval = 60
WindowTitle = Pyblish (Maya)
ContextLabel = Maya
Qt: Dead lock detected while activating a BlockingQueuedConnection: Sender is TmainThreadScriptExecutor(0x25e23f917a0), receiver is TmainThreadScriptExecutor(0x25e23f917a0)

So Pyblish-QML does try to start and actually pops up but instantly hangs as soon as it tries to push a command back into the Mayapy process, using this maya.utils.executeInMainThreadWithResult. This might be fixed by recognizing correctly that it’s a Maya standalone process and using another method of evaluating in the local process in that case.

Pyblish-Lite however does not function that way and just runs the code locally. As such, Pyblish-lite should work - but I haven’t tested it.

1 Like

Both GUIs are meant to work, but it’s possible there has been some regression as it isn’t being tested automatically (a hard thing to do).

At the very least you should be able to call something like this from mayapy.

from pyblish import util

This will trigger a publish much like Lite and QML, but without a user interface around it. It will return a Context(), with the published instances and results, as context[:] and["results"] respectively. You can use that to print a summary, see here for an example of that.

To better help you with the GUI side, it would be great if you could share your OS and the commands you’ve run to reach the problem. That way someone could potentially try and reproduce it and potentially fix it.

1 Like

Thanks all :slight_smile:

from pyblish import util

and the context prints did the trick.

As in, you found a potential solution and have a GUI open now? :wink:

Something weird happened where I wanted to reply, but it somehow edited this post instead (so all the “edits” on this post are nonsense

Well i didnt want my own gui for the standalone.
I have another program from which i start the standalone and in which i run pyblish :slight_smile:

Glad to hear you are able to continue!

Just wondering, what other “program” are you launching from? I initially prototyped a tool to submit a scene for background processing, however I found that actually Pyblish QML could do the trick too using Pyblish targets.

That way Artists are very familiar, whether they are publishing their scene locally or are submitting it for publishing on the farm. More details here.

Well it’s just a small qt program where i can pick a bundle of pyblish plugins and then start maya in standalone and run them. I can also open the qt program in ordinary maya and run the pyblish in the current scene.