示例#1
0
    def launch(self,
               scene_file="",
               headless=False,
               responsive_ui=False,
               blocking=False,
               write_coppeliasim_stdout_to_file=False) -> None:
        """Launches CoppeliaSim.

        Launches the UI thread, waits until the UI thread has finished, this
        results in the current thread becoming the simulation thread.

        :param scene_file: The scene file to load. Empty string for empty scene.
        :param headless: Run CoppeliaSim in simulation mode.
        :param responsive_ui: If True, then a separate thread will be created to
            asynchronously step the UI of CoppeliaSim. Note, that will reduce
            the responsiveness of the simulation thread.
        :param blocking: Causes CoppeliaSim to launch as if running the default
            c++ client application. This is causes the function to block.
            For most users, this will be set to False.
        :param write_coppeliasim_stdout_to_file: Causes CoppeliaSim to write the stdout to files in /tmp, rather than
            the terminal stdout as the python script is run. This helps reduce screen clutter, particularly if using
            multiple PyRep instances with multiprocessing, for example.
        """
        abs_scene_file = os.path.abspath(scene_file)
        if len(scene_file) > 0 and not os.path.isfile(abs_scene_file):
            raise PyRepError('Scene file does not exist: %s' % scene_file)
        cwd = os.getcwd()
        self._ui_thread = threading.Thread(
            target=self._run_ui_thread,
            args=(abs_scene_file, headless, write_coppeliasim_stdout_to_file))
        self._ui_thread.daemon = True
        self._ui_thread.start()

        while not sim.simExtCanInitSimThread():
            time.sleep(0.1)

        sim.simExtSimThreadInit()
        time.sleep(0.2)  # Stops CoppeliaSim crashing if restarted too quickly.

        if blocking:
            while not sim.simExtGetExitRequest():
                sim.simExtStep()
            self.shutdown()
        elif responsive_ui:
            self._responsive_ui_thread = threading.Thread(
                target=self._run_responsive_ui_thread)
            self._responsive_ui_thread.daemon = True
            try:
                self._responsive_ui_thread.start()
            except (KeyboardInterrupt, SystemExit):
                if not self._shutting_down:
                    self.shutdown()
                sys.exit()
            self.step()
        else:
            self.step()
        os.chdir(cwd)  # Go back to the previous cwd
示例#2
0
文件: pyrep.py 项目: wkoa/PyRep
    def launch(self,
               scene_file: str = "",
               headless: bool = False,
               responsive_ui: bool = False,
               blocking: bool = False,
               verbosity: Verbosity = Verbosity.NONE) -> None:
        """Launches CoppeliaSim.

        Launches the UI thread, waits until the UI thread has finished, this
        results in the current thread becoming the simulation thread.

        :param scene_file: The scene file to load. Empty string for empty scene.
        :param headless: Run CoppeliaSim in simulation mode.
        :param responsive_ui: If True, then a separate thread will be created to
            asynchronously step the UI of CoppeliaSim. Note, that will reduce
            the responsiveness of the simulation thread.
        :param blocking: Causes CoppeliaSim to launch as if running the default
            c++ client application. This is causes the function to block.
            For most users, this will be set to False.
        :param verbosity: The verbosity level for CoppeliaSim.
            Usually Verbosity.NONE or Verbosity.LOAD_INFOS.
        """
        abs_scene_file = os.path.abspath(scene_file)
        if len(scene_file) > 0 and not os.path.isfile(abs_scene_file):
            raise PyRepError('Scene file does not exist: %s' % scene_file)
        cwd = os.getcwd()
        self._ui_thread = threading.Thread(target=self._run_ui_thread,
                                           args=(abs_scene_file, headless,
                                                 verbosity))
        self._ui_thread.daemon = True
        self._ui_thread.start()

        while not sim.simExtCanInitSimThread():
            time.sleep(0.1)

        sim.simExtSimThreadInit()
        time.sleep(0.2)  # Stops CoppeliaSim crashing if restarted too quickly.

        if blocking:
            while not sim.simExtGetExitRequest():
                sim.simExtStep()
            self.shutdown()
        elif responsive_ui:
            self._responsive_ui_thread = threading.Thread(
                target=self._run_responsive_ui_thread)
            self._responsive_ui_thread.daemon = True
            try:
                self._responsive_ui_thread.start()
            except (KeyboardInterrupt, SystemExit):
                if not self._shutting_down:
                    self.shutdown()
                sys.exit()
            self.step()
        else:
            self.step()
        os.chdir(cwd)  # Go back to the previous cwd
示例#3
0
文件: pyrep.py 项目: wkoa/PyRep
 def _run_responsive_ui_thread(self) -> None:
     while True:
         if not self.running:
             with self._step_lock:
                 if self._shutting_down or sim.simExtGetExitRequest():
                     break
                 sim.simExtStep(False)
         time.sleep(0.01)
     # If the exit request was from the UI, then call shutdown, otherwise
     # shutdown caused this thread to terminate.
     if not self._shutting_down:
         self.shutdown()