sandbox/executor.py
def execute(self) -> dict:
        """Execute each commands in the container."""
        start = time.time()
        
        self._move_env_to_container()
        
        execution = list()
        timeout = settings.EXECUTE_TIMEOUT
        for command in self.commands:
            command.timeout = min(command.timeout, timeout)
            status, exec_result = command.execute(self.sandbox.container)
            execution.append(exec_result)
            if not status:
                status = exec_result["exit_code"]
                break
            timeout -= max(exec_result["time"], 0)
        else:
            status = 0
        
        result = None
        if self.result_path is not None:
            try:
                result = self._get_result()
            except FileNotFoundError:
                status = SandboxErrCode.RESULT_NOT_FOUND.value
            except UnicodeDecodeError:
                status = SandboxErrCode.RESULT_NOT_UTF8.value
        
        response = {
            "status":     status,
            "execution":  execution,
            "total_time": time.time() - start,
        }
        
        if self.save:
            expire = timezone.now() + timedelta(seconds=settings.ENVIRONMENT_EXPIRATION)
            response["environment"] = self.env_uuid
            response["expire"] = expire.isoformat()
            # Remove the one used by the container as it will cause an error in extract_env if the
            # destination already exists.
            os.remove(self.env_path)
            self.sandbox.extract_env(self.env_uuid)
        else:
            os.remove(self.env_path)
        
        if result is not None:
            response["result"] = result
        
        return response
Execute each commands in the container.
Execute each commands in the container.
Execute each commands in the container .
def execute(self) -> dict:
        start = time.time()
        self._move_env_to_container()
        execution = list()
        timeout = settings.EXECUTE_TIMEOUT
        for command in self.commands:
            command.timeout = min(command.timeout, timeout)
            status, exec_result = command.execute(self.sandbox.container)
            execution.append(exec_result)
            if not status:
                status = exec_result["exit_code"]
                break
            timeout -= max(exec_result["time"], 0)
        else:
            status = 0
        result = None
        if self.result_path is not None:
            try:
                result = self._get_result()
            except FileNotFoundError:
                status = SandboxErrCode.RESULT_NOT_FOUND.value
            except UnicodeDecodeError:
                status = SandboxErrCode.RESULT_NOT_UTF8.value
        response = {
            "status":     status,
            "execution":  execution,
            "total_time": time.time() - start,
        }
        if self.save:
            expire = timezone.now() + timedelta(seconds=settings.ENVIRONMENT_EXPIRATION)
            response["environment"] = self.env_uuid
            response["expire"] = expire.isoformat()
            os.remove(self.env_path)
            self.sandbox.extract_env(self.env_uuid)
        else:
            os.remove(self.env_path)
        if result is not None:
            response["result"] = result
        return response
def execute ( self ) -> dict : start = time . time ( ) self . _move_env_to_container ( ) execution = list ( ) timeout = settings . EXECUTE_TIMEOUT for command in self . commands : command . timeout = min ( command . timeout , timeout ) status , exec_result = command . execute ( self . sandbox . container ) execution . append ( exec_result ) if not status : status = exec_result [ "exit_code" ] break timeout -= max ( exec_result [ "time" ] , 0 ) else : status = 0 result = None if self . result_path is not None : try : result = self . _get_result ( ) except FileNotFoundError : status = SandboxErrCode . RESULT_NOT_FOUND . value except UnicodeDecodeError : status = SandboxErrCode . RESULT_NOT_UTF8 . value response = { "status" : status , "execution" : execution , "total_time" : time . time ( ) - start , } if self . save : expire = timezone . now ( ) + timedelta ( seconds = settings . ENVIRONMENT_EXPIRATION ) response [ "environment" ] = self . env_uuid response [ "expire" ] = expire . isoformat ( ) os . remove ( self . env_path ) self . sandbox . extract_env ( self . env_uuid ) else : os . remove ( self . env_path ) if result is not None : response [ "result" ] = result return response
Execute each commands in the container.
Execute each commands in the container .
"""Execute each commands in the container.""" # Remove the one used by the container as it will cause an error in extract_env if the # destination already exists.
self