-
Notifications
You must be signed in to change notification settings - Fork 0
/
@!
96 lines (83 loc) · 2.53 KB
/
@!
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
84
85
86
87
88
89
90
91
92
93
94
95
96
import asyncio
import random
import copy
import queue
import time
import sys
try:
a={}
print(a[1])
except:
print(sys.exc_info())
class test(object):
def __init__(self,*args,**kwargs):
self.args = args
self.kwargs = kwargs
def identity (self):
return self
objIn=test('arg-1','arg-2','arg-3','arg-n',key1=1,key2=2,key3=3,keyn='n')
objOut=objIn.identity()
print('args=',objOut.args,'kwargs=',objOut.kwargs)
objIn.args = (1,2)
print('args=',objOut.args,'kwargs=',objOut.kwargs)
#If you want just the arguments to be printed...
print(test('arg-1','arg-2','arg-3','arg-n',key1=1,key2=2,key3=3,keyn='n').identity().args)
print(test('arg-1','arg-2','arg-3','arg-n',key1=1,key2=2,key3=3,keyn='n').identity().kwargs)
models={}
ports={}
Q1=queue.Queue()
Q2=queue.Queue()
Q3=queue.Queue()
Q4=queue.Queue()
Q1.put(1)
Q2.put(1)
Q4.put(1)
Q3.put(2)
Q1.put(1)
Q2.put(1)
Q4.put(1)
Q3.put(2)
q1=[Q1]
q2=[Q2] #,Q3,Q1]
q3=[Q3] #,Q4,Q1]
q4=[Q4] #,Q2]
ports['port1']=copy.copy(q1)
ports['port2']=copy.copy(q2)
models['model1']=copy.copy(ports)
ports['port1']=copy.copy(q3)
ports['port2']=copy.copy(q4)
models['model2']=copy.copy(ports)
def getRandomQs(models,method,filterEmpty=True):
q=[]
for model,ports in models.items():
if (q and method == 'getAny'): break
for port,queues in ports.items():
if queues:
if filterEmpty: #Filter empty queues for get
filtered_q = list(filter(lambda x:x.qsize() > 0, queues))
else: # Leave empty queues for put
filtered_q = list(filter(lambda x:x.qsize() >= 0, queues))
if filtered_q:
q.append(filtered_q[random.randint(0,len(filtered_q)-1)])
if (method == 'getAll'):
if list(set(queues) - set(filtered_q)):
q.append(list(set(queues) - set(filtered_q))[0])
elif (q and method == 'getAny'): break
#if q: break
return q
def getPut(models,method=None,**item):
kwargs = {}
if (method == 'put'):
for queue in getRandomQs(models,method,filterEmpty=False):
print(item)
queue.put(item)
print(queue.get())
else:
for kv in getRandomQs(models,method,filterEmpty=True):
print(kv.get_nowait())
kwargs.update(kv.get_nowait())
return kwargs
getPut(models,item={'1':'one'},method='put')
getPut(models,item={'2':'two'},method='put')
print(getPut(models,method='getAny'))
print(getPut(models,method='getAll'))