* Determine worker count based on config and environment * Priority: config.workers > PROMPTFOO_PYTHON_WORKERS env > cliState.maxConcurrency (-j flag) > default 1 * * Explicit Python-specific settings (config.workers, env var) take precedence over * general concurrency hints (-j flag) be
()
| 266 | * memory constraints or non-thread-safe scripts. |
| 267 | */ |
| 268 | private getWorkerCount(): number { |
| 269 | // 1. Explicit config.workers (highest priority - user knows their script's requirements) |
| 270 | if (this.config.workers !== undefined) { |
| 271 | if (this.config.workers < 1) { |
| 272 | logger.warn(`Invalid worker count ${this.config.workers} in config, using minimum of 1`); |
| 273 | return 1; |
| 274 | } |
| 275 | logger.debug(`Python provider using ${this.config.workers} workers (from config.workers)`); |
| 276 | return this.config.workers; |
| 277 | } |
| 278 | |
| 279 | // 2. Environment variable (explicit Python-specific setting) |
| 280 | const envWorkers = getEnvInt('PROMPTFOO_PYTHON_WORKERS'); |
| 281 | if (envWorkers !== undefined) { |
| 282 | if (envWorkers < 1) { |
| 283 | logger.warn( |
| 284 | `Invalid worker count ${envWorkers} in PROMPTFOO_PYTHON_WORKERS, using minimum of 1`, |
| 285 | ); |
| 286 | return 1; |
| 287 | } |
| 288 | logger.debug(`Python provider using ${envWorkers} workers (from PROMPTFOO_PYTHON_WORKERS)`); |
| 289 | return envWorkers; |
| 290 | } |
| 291 | |
| 292 | // 3. CLI -j flag via cliState (general concurrency hint, only when explicitly set) |
| 293 | if (cliState.maxConcurrency !== undefined) { |
| 294 | if (cliState.maxConcurrency < 1) { |
| 295 | logger.warn( |
| 296 | `Invalid worker count ${cliState.maxConcurrency} from -j flag, using minimum of 1`, |
| 297 | ); |
| 298 | return 1; |
| 299 | } |
| 300 | logger.debug(`Python provider using ${cliState.maxConcurrency} workers (from -j flag)`); |
| 301 | return cliState.maxConcurrency; |
| 302 | } |
| 303 | |
| 304 | // 4. Default: 1 worker (memory-efficient, backward compatible) |
| 305 | logger.debug('Python provider using 1 worker (default)'); |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Execute the Python script with the specified API type |