Beispiel #1
0
        public IEnumerator StandalonePublish()
        {
            // Restart the server, making sure there is no Shotgun client
            PythonRunner.StopServer(false);

            // Make sure the Shotgun client has stopped
            double initTime = EditorApplication.timeSinceStartup;

            while (Bootstrap.IsClientAlive())
            {
                if (EditorApplication.timeSinceStartup - initTime > shutdownTimeout)
                {
                    Assert.That(false, Is.True);
                }
                System.Threading.Thread.Sleep(100);
            }
            // Bootstrap Shotgun with our test client
            Bootstrap.SpawnClient(clientPath);

            // Give some time for the client to connect
            yield return(PythonRunner.WaitForConnection(Constants.clientName, connectionTimeout));

            // Wait until the client is fully bootstrapped
            initTime = EditorApplication.timeSinceStartup;
            while (!PythonRunner.CallServiceOnClient(Constants.clientName, "bootstrapped"))
            {
                if (EditorApplication.timeSinceStartup - initTime > bootstrapTimeout)
                {
                    break;
                }
                yield return(null);
            }

            // Fake a recording by copying a video file in the right location
            string videoFilePath   = Path.GetFullPath($"{testsPath}/standalone_publish.mp4");
            var    destinationPath = Path.Combine(System.IO.Path.GetTempPath(), Application.productName);

            destinationPath += ".mp4";

            System.IO.File.Copy(videoFilePath, destinationPath, true);

            Service.Call("standalone_publish");

            // Wait until the client has finished publishing
            initTime = EditorApplication.timeSinceStartup;
            while (!PythonRunner.CallServiceOnClient(Constants.clientName, "published"))
            {
                if (EditorApplication.timeSinceStartup - initTime > publishTimeout)
                {
                    break;
                }
                yield return(null);
            }

            // Upon success, the Python script creates a game object named
            // after the product name
            GameObject go = GameObject.Find(Application.productName);

            Assert.IsNotNull(go);
        }
        // Returns whether the client is connected or not.
        // If the client is not connected but is alive (see IsAlive), we assume
        // it is reconnecting and the method will wait (blocking the main thread)
        // for a certain time until the client reconnects.
        internal static bool EnsureConnection()
        {
            if (!IsAlive)
            {
                return(false);
            }

            // The client is alive. Give it some time to reconnect if it
            // is not
            var iter = PythonRunner.WaitForConnection(Constants.clientName, Constants.clientReconnectionTimeout);

            bool moving = true;

            while (moving)
            {
                using (Py.GIL())
                {
                    moving = iter.MoveNext();

                    // Use the Python time module to sleep. This gives the
                    // interpreter a chance to schedule its threads
                    dynamic time = Py.Import("time");
                    time.sleep(Constants.interpreterSleepPeriod);
                }
            }

            if (PythonRunner.IsClientConnected(Constants.clientName))
            {
                return(true);
            }

            // The client never reconnected
            UnityEngine.Debug.LogWarning("The Shotgun client process is not connected. Please reimport the Shotgun package");

            // Client is not connected, update the PID
            PID = -1;
            return(false);
        }
Beispiel #3
0
    private static IEnumerator WaitForWorkerAndInitialize()
    {
        yield return(PythonRunner.WaitForConnection(WORKER_NAME));

        Services.Init(FindPythonNodes());
    }