| 47 | |
| 48 | |
| 49 | class Once(): |
| 50 | _id = {} |
| 51 | |
| 52 | def __init__(self, what, who=log, per=1e12): |
| 53 | """ Do who(what) once per seconds. |
| 54 | what: args for who |
| 55 | who: callable |
| 56 | per: frequency in seconds. |
| 57 | """ |
| 58 | assert callable(who) |
| 59 | now = time.time() |
| 60 | if what not in Once._id or now - Once._id[what] > per: |
| 61 | who(what) |
| 62 | Once._id[what] = now |
| 63 | |
| 64 | |
| 65 | class TicToc: |
no outgoing calls
no test coverage detected