Changeset 491:690563fa7a32
- Timestamp:
- 10/13/08 12:33:38
(3 months ago)
- Author:
- Brian Warner <warner@allmydata.com>
- branch:
- default
- Message:
logging: replace itertools.count() with a non-overflowing version, closes #99
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r490 |
r491 |
|
| 1 | 1 | 2008-10-13 Brian Warner <warner@allmydata.com> |
|---|
| | 2 | |
|---|
| | 3 | * foolscap/logging/log.py (Count): replace itertools.count with a |
|---|
| | 4 | version that doesn't overflow at 2**31-1 (thanks to Zooko for the |
|---|
| | 5 | patch). Closes #99. |
|---|
| | 6 | (FoolscapLogger.__init__): use it |
|---|
| 2 | 7 | |
|---|
| 3 | 8 | * foolscap/pb.py (Listener.startFactory): add log facility |
|---|
| r471 |
r491 |
|
| 1 | 1 | |
|---|
| 2 | 2 | import os, sys, time, pickle, weakref |
|---|
| 3 | | import itertools |
|---|
| 4 | 3 | import traceback |
|---|
| 5 | 4 | import collections |
|---|
| … | … | |
| 34 | 33 | |
|---|
| 35 | 34 | |
|---|
| | 35 | class Count: |
|---|
| | 36 | """A fixed version of itertools.count . |
|---|
| | 37 | |
|---|
| | 38 | This class counts up from zero, just like the Python 2.5.2 docs claim |
|---|
| | 39 | that itertools.count() does, but this class does not overflow with an |
|---|
| | 40 | error like itertools.count() does: |
|---|
| | 41 | |
|---|
| | 42 | File 'foolscap/logging/log.py', line 137, in msg |
|---|
| | 43 | num = self.seqnum.next() |
|---|
| | 44 | exceptions.OverflowError: cannot count beyond PY_SSIZE_T_MAX |
|---|
| | 45 | """ |
|---|
| | 46 | |
|---|
| | 47 | def __init__(self, firstval=0): |
|---|
| | 48 | self.n = firstval - 1 |
|---|
| | 49 | |
|---|
| | 50 | def next(self): |
|---|
| | 51 | self.n += 1 |
|---|
| | 52 | return self.n |
|---|
| | 53 | |
|---|
| 36 | 54 | class FoolscapLogger: |
|---|
| 37 | 55 | DEFAULT_SIZELIMIT = 100 |
|---|
| … | … | |
| 41 | 59 | def __init__(self): |
|---|
| 42 | 60 | self.incarnation = self.get_incarnation() |
|---|
| 43 | | self.seqnum = itertools.count(0) |
|---|
| | 61 | self.seqnum = Count() |
|---|
| 44 | 62 | self.facility_explanations = {} |
|---|
| 45 | 63 | self.buffer_sizes = {} # k: facility or None, v: dict(level->sizelimit) |
|---|