问题 / #2908

#2908 strata_bench.py: NameError: name 'port' is not defined when it starts the server itself (0.1.45, since #2330)

open · @K8nsch · 1 评论 · 去 GitHub 看

BenchmarksSetup & installModels & quantsWindows

说明

**What happens**

With no Strata server running, `tools\strata_bench.py --config strata-iq3_s.json --long` stops at once:

```
  File "C:\Tools\Strata\tools\strata_bench.py", line 990, in main
    say(f"Starting {cfg_path.name} on port {port} (loading takes 1-3 minutes; the PC may be slow meanwhile) ...")
NameError: name 'port' is not defined
```

**Cause**

69fe4055 (#2330, PR #2362) replaced

```python
port = a.port or int(cfg.get("port", 8080))
base = f"http://127.0.0.1:{port}"
```

with `base = server_base(cfg.get("host"), a.port or int(cfg.get("port", 8080)))`, so `port` is no longer bound, but lines 987, 990 and 991 (`start_server(cfg_path, port, ...)`) still use it. Only the path where the bench starts the server is affected; against a running server (or with `--url`) it works.

**Fix (suggestion)**

```python
port = a.port or int(cfg.get("port", 8080))
base = server_base(cfg.get("host"), port)
```

(`port` is only needed in the branch with a config, which is the only branch that reaches line 987.)

**Setup:** Windows 11, 0.1.45 release zip (`strata-windows-x64.zip`), repo at 477ac13c. Worked around by starting the server first; the bench then uses the running server.

本站相关内容

相关页面的快捷入口。