Commit 2eabd63
Reuse ISO-TP stacks across DIDs of the same addressing scheme
python-can-isotp's TransportLayer is designed for long-lived stacks:
start() spins up two daemon threads and initializes internal state
(timers, sequence counters, queues) that the library expects to persist
across transfers. Building stacks per DID created ~500 threads per
functional / broadcast read and discarded the layer's internal state
nine times per run.
Move stack construction and start()/stop() into _read_all_dids, scoped
to each addressing scheme. _read_did becomes a pure send + poll helper.
Stacks now live across all three DIDs of their scheme and are torn down
exactly three times per run. A try/finally guarantees stop() runs even
if a DID's recv loop raises.
Header-based filtering in the recv loop already discards any cross-DID
residue in the queues, so reusing stacks across DIDs is safe.
Test runtime drops from 66.7 s to 22.7 s without any change to message
handling or CAN traffic.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent aa75e5c commit 2eabd63
1 file changed
Lines changed: 21 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
232 | 243 | | |
233 | 244 | | |
234 | 245 | | |
| |||
255 | 266 | | |
256 | 267 | | |
257 | 268 | | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
| 269 | + | |
| 270 | + | |
267 | 271 | | |
268 | 272 | | |
269 | 273 | | |
| |||
291 | 295 | | |
292 | 296 | | |
293 | 297 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| |||
0 commit comments