Start the puppet main process.
(self)
| 167 | |
| 168 | def start_puppet(self, monitor=None): |
| 169 | """Start the puppet main process on the given monitor connector, or the focused one.""" |
| 170 | # Only a lock this launch creates may be removed on stop. Another |
| 171 | # puppet, such as one started by the assistant, shares this path. |
| 172 | self.owns_lockfile = not os.path.isfile(self.lockfile) |
| 173 | |
| 174 | # Get the src directory for proper module imports |
| 175 | src_dir = os.path.dirname(self.main_py) |
| 176 | project_root = os.path.dirname(src_dir) |
| 177 | |
| 178 | # Open a log file to capture output (keep it open) |
| 179 | log_path = os.path.join(project_root, "puppet.log") |
| 180 | self.log_file = open(log_path, "w") |
| 181 | |
| 182 | # Start the main.py process directly (cli.sh logic is handled in GUI) |
| 183 | env = os.environ.copy() |
| 184 | env['PYTHONPATH'] = src_dir |
| 185 | |
| 186 | command = ["python3", self.main_py] |
| 187 | if monitor: |
| 188 | command += ["--monitor", monitor] |
| 189 | self.process = subprocess.Popen( |
| 190 | command, |
| 191 | stdout=self.log_file, |
| 192 | stderr=subprocess.STDOUT, |
| 193 | env=env, |
| 194 | cwd=src_dir |
| 195 | ) |
| 196 | return self.process |
| 197 |