-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatus.py
More file actions
executable file
·38 lines (32 loc) · 912 Bytes
/
status.py
File metadata and controls
executable file
·38 lines (32 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
#-*- coding:utf-8 -*-
__all__ = ['Status']
import threading
class Status(object):
def __init__(self):
self.total_fetched = 0
self.fetch_failed = 0
self.fetch_matched = 0
self.lock = threading.Lock()
def update(self, failed=0, matched=0):
self.lock.acquire()
self.total_fetched += 1
if failed:
self.fetch_failed += 1
if matched:
self.fetch_matched += 1
self.lock.release()
def clear(self):
self.lock.acquire()
self.total_fetched = 0
self.fetch_failed = 0
self.fetch_matched = 0
self.lock.release()
def get(self):
ret = {}
self.lock.acquire()
ret['total'] = self.total_fetched
ret['failed'] = self.fetch_failed
ret['matched'] = self.fetch_matched
self.lock.release()
return ret