コード例 #1
0
        // 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);
        }