UE5 Python Remote Execution won't detect UE5 on first launch

I’m trying to connect to UE5 from Python using Remote Execution. I have it enabled in my UE5 Project Settings:

image

But it seems like I cannot detect any running instances of UE5 unless I manually toggle this option OFF and then ON again :face_with_raised_eyebrow:

So basically it goes like this: I turn my PC on in the morning and I launch UE5. Once it’s open, I run the following python code inside Maya 2022.5 or a pure Python (3.11) interpretor:

import remote_execution
remEx = remote_execution.RemoteExecution()
remEx.start()

Then I execute:

print(remEx.remote_nodes)
# Result: [] #

And I always get back an empty list, no instances of UE5 found running. However, if I then toggle the Enable Remote Execution option OFF, and then back ON again in UE5 Project Settings, the same code immediately starts working fine:

print(remEx.remote_nodes)
# Result: [{'engine_root': 'E:/ue5/5.3/Engine/',
  'engine_version': '5.3.2-0+UE5',
  'machine': 'WPC8008135',
  'node_id': 'BE379C85332ABAD6E099EB7ED5BB2C5B',
  'project_name': 'MacGuffin',
  'project_root': 'E:/macguffin/',
  'user': 'Nathan'}] #

From that point onwards, if I close and re-open UE5, Maya, or Python any number of times in any order, the detection code above still works fine every time… until I shut down and reboot my PC, then I have to go through the option toggle off/on rigmarole again.

Does anyone know why this is happening or how I could fix it? toggling that option off/on every morning isn’t exactly back-breaking, but it’s pointlessly tedious, especially for the other artists who I just want to be able to use this tool without messing around with their project options every morning too.

I have a blurry memory of hitting something similar. If i recall .remote_nodes is a property that queries for nodes on a thread and then caches them. The first time its called it might return before the thread finds any nodes. Some dirty hack like this might work

        total_sleep = 0
        while not remEx.remote_nodes:
            time.sleep(1)
            total_sleep += 1
            if total_sleep > timeout:
                 # no joy
                raise 
        return remEx.remote_nodes

thanks for the reply, yeah, the timer thing is another issue which I already knew about (I should have mentioned that in the original post), but this is not related to that. It doesn’t matter how long I wait the very first time, no nodes are ever detected until I do the disable/re-enable option described above. it’s very odd.