-
Notifications
You must be signed in to change notification settings - Fork 8
/
queue_server.py
83 lines (73 loc) · 2.07 KB
/
queue_server.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#-*- coding:utf-8 -*-
from multiprocessing import Manager
class Queue_server(object):
'''
初始话公众号队列
@param Tuple wx_lists 公众号列表
'''
def __init__(self ,wx_lists=()):
self.__queue = Manager().Queue(-1)
self.init_wx_lists(wx_lists)
self.__fail_list = Manager().list()
'''
初始话公众号队列
@param Tuple wx_lists 公众号列表
'''
def init_wx_lists(self ,wx_lists=()):
for wx in wx_lists:
self.put(wx)
'''
添加元素
@param mixed value 要添加的元素
'''
def put(self ,value):
self.__queue.put(value)
'''
弹出元素
@return mixed
'''
def get(self):
if not self.empty():
return self.__queue.get()
return False
'''
获取队列
@return mixed
'''
def get_wx_lists_queue(self):
return self.__queue
'''
获取队列大小
@return int
'''
def get_size(self):
return self.__queue.qsize()
'''
队列是否为空
@return bool
'''
def empty(self):
return self.__queue.empty()
'''
添加失败数据
@param tuple wx_data 公众号信息
@return bool
'''
def put_fail_wx(self , wx_data):
self.__fail_list.append(wx_data)
'''
打印失败列表
'''
def print_fail_list(self ,flush=None):
if len(self.__fail_list) > 0 :
for fail in self.__fail_list:
self.put(fail)
print 'the fail wx : {0}' . format(fail)
if not flush:
self.__fail_list = Manager().list()
elif flush:
print 'all success'
#判断是否有错
def is_have_failed(self):
#判断是否有失败的公众号重新加入队列中
return not self.empty()