Start an orca server if none is running. If a server is already running, then reset the timeout countdown Returns ------- None
()
| 1227 | |
| 1228 | # Launch or get server |
| 1229 | def ensure_server(): |
| 1230 | """ |
| 1231 | Start an orca server if none is running. If a server is already running, |
| 1232 | then reset the timeout countdown |
| 1233 | |
| 1234 | Returns |
| 1235 | ------- |
| 1236 | None |
| 1237 | """ |
| 1238 | |
| 1239 | # Validate psutil |
| 1240 | if psutil is None: |
| 1241 | raise ValueError( |
| 1242 | """\ |
| 1243 | Image generation requires the psutil package. |
| 1244 | |
| 1245 | Install using pip: |
| 1246 | $ pip install psutil |
| 1247 | |
| 1248 | Install using conda: |
| 1249 | $ conda install psutil |
| 1250 | """ |
| 1251 | ) |
| 1252 | |
| 1253 | # Validate requests |
| 1254 | if not get_module("requests"): |
| 1255 | raise ValueError( |
| 1256 | """\ |
| 1257 | Image generation requires the requests package. |
| 1258 | |
| 1259 | Install using pip: |
| 1260 | $ pip install requests |
| 1261 | |
| 1262 | Install using conda: |
| 1263 | $ conda install requests |
| 1264 | """ |
| 1265 | ) |
| 1266 | |
| 1267 | if not config.server_url: |
| 1268 | # Validate orca executable only if server_url is not provided |
| 1269 | if status.state == "unvalidated": |
| 1270 | validate_executable() |
| 1271 | # Acquire lock to make sure that we keep the properties of orca_state |
| 1272 | # consistent across threads |
| 1273 | with orca_lock: |
| 1274 | # Cancel the current shutdown timer, if any |
| 1275 | if orca_state["shutdown_timer"] is not None: |
| 1276 | orca_state["shutdown_timer"].cancel() |
| 1277 | |
| 1278 | # Start a new server process if none is active |
| 1279 | if orca_state["proc"] is None: |
| 1280 | # Determine server port |
| 1281 | if config.port is None: |
| 1282 | orca_state["port"] = find_open_port() |
| 1283 | else: |
| 1284 | orca_state["port"] = config.port |
| 1285 | |
| 1286 | # Build orca command list |
no test coverage detected