killing thread ?

Tim Peters at
Sat Jan 25 13:15:16 CET 2003

[Paul Rubin]
> ...
> CPU time may be hard to measure on a per-thread basis, but certainly it
> can count byte codes executed, which should be enough for the purpose.

Count of bytecodes executed is monotonic with CPU cycles consumed, but
there's no definable relationship beyond "monotonic with" -- there's no
upper bound on how much work a single bytecode can require before the PVM is
entered again.  For example, a single bytecode can kick off a (very) long
int division requiring CPU minutes, or a regexp search requiring CPU
millennia.  Here's a cute one:

a = []
for i in range(4): a.append(a)
b = []
for i in range(4): b.append(b)
equal = a == b

The opcode for "==" there won't return until about a century has passed:
counting bytecodes is simply useless as a protection against DOS attacks of
a CPU-hogging nature.

resource-limitations-are-an-os's-job-ly y'rs  - tim

More information about the Python-list mailing list