Browse Source

auto commit

master
jfinn 2 years ago
parent
commit
3e1819abbd
1 changed files with 6 additions and 108 deletions
  1. 6
    108
      wsps/tasks_loop.py

+ 6
- 108
wsps/tasks_loop.py View File

13
 from asgiref.sync import async_to_sync,sync_to_async
13
 from asgiref.sync import async_to_sync,sync_to_async
14
 
14
 
15
 
15
 
16
-'''
17
-	umod
18
-# '''
19
-
20
-
21
 
16
 
22
 p=print
17
 p=print
23
 
18
 
29
 	return redis.Redis(host='localhost', port=6379, db=1,charset="utf-8", decode_responses=True, encoding_errors="backslashreplace")
24
 	return redis.Redis(host='localhost', port=6379, db=1,charset="utf-8", decode_responses=True, encoding_errors="backslashreplace")
30
 def connect_redis():
25
 def connect_redis():
31
 	return redis.Redis(host='localhost', port=6379, db=0,charset="utf-8", decode_responses=True, encoding_errors="backslashreplace")
26
 	return redis.Redis(host='localhost', port=6379, db=0,charset="utf-8", decode_responses=True, encoding_errors="backslashreplace")
32
-	# return redis.Redis(host='localhost', port=6379,charset="utf-8", decode_responses=True, encoding_errors="backslashreplace")
33
-	r'''
34
-
35
-	return {
36
-	 "rconn0":redis.Redis(host='localhost', port=6379, db=0,charset="utf-8", decode_responses=True, encoding_errors="backslashreplace"),
37
-	 "rconn1":redis.Redis(host='localhost', port=6379, db=1,charset="utf-8", decode_responses=True, encoding_errors="backslashreplace"),
38
-	}
39
-	# '''
40
-
41
 
27
 
42
 
28
 
43
 def eclass_factory(n):
29
 def eclass_factory(n):
49
 	return ret
35
 	return ret
50
 
36
 
51
 
37
 
52
-'''
53
-# '''
54
-
55
 
38
 
56
 
39
 
57
 
40
 
68
 
51
 
69
 
52
 
70
 
53
 
71
-
72
-
73
-
74
-
75
-
76
-
77
-verbose = print
54
+# verbose = print
78
 verbose=nop
55
 verbose=nop
56
+
79
 class DbgMixin:
57
 class DbgMixin:
80
 	async def ws_rec(self,text_data,*a,**kw):
58
 	async def ws_rec(self,text_data,*a,**kw):
81
 		# if "dbg" in 
59
 		# if "dbg" in 
87
 class AconMixin(DbgMixin):
65
 class AconMixin(DbgMixin):
88
 # class AconMixin:
66
 # class AconMixin:
89
 	async def connect(self):
67
 	async def connect(self):
90
-		# print("-----------CONNECTING async def connect")
91
-		# p("ACON!!!!!!!!!!!!!!!!!!!!!!!!!!!")
92
-		p(flush=True)
68
+		p(end="",flush=True)
93
 		await self.accept()
69
 		await self.accept()
94
 		verbose("<MRO")
70
 		verbose("<MRO")
95
 
71
 
98
 		await self.call_all_mro("ws_conn")
74
 		await self.call_all_mro("ws_conn")
99
 		await self.call_all_mro("ws_conn2")
75
 		await self.call_all_mro("ws_conn2")
100
 		verbose("/MRO>")
76
 		verbose("/MRO>")
101
-		# await self.ws_conn_once(event)		
102
 		await self.ws_conn_once()	   
77
 		await self.ws_conn_once()	   
103
 	async def ws_conn_once(self, *a,**kw):pass
78
 	async def ws_conn_once(self, *a,**kw):pass
104
 	async def ws_disconn_once(self, *a,**kw):pass
79
 	async def ws_disconn_once(self, *a,**kw):pass
105
 	async def ws_rec_once(self, *a,**kw):pass
80
 	async def ws_rec_once(self, *a,**kw):pass
106
 	async def receive(self, *a,**kw):
81
 	async def receive(self, *a,**kw):
107
-		# print("REC")
108
-		# print("-----------REC")
109
 		await self.call_all_mro("ws_rec",*a,**kw)
82
 		await self.call_all_mro("ws_rec",*a,**kw)
110
 		await self.ws_rec_once(*a,**kw)
83
 		await self.ws_rec_once(*a,**kw)
111
 		print("",end="",flush=True)
84
 		print("",end="",flush=True)
114
 		called = set([None])
87
 		called = set([None])
115
 		for cls_obj in self.__class__.__mro__:
88
 		for cls_obj in self.__class__.__mro__:
116
 			mthd = getattr(cls_obj,mthd_name,None)
89
 			mthd = getattr(cls_obj,mthd_name,None)
117
-			# print("~",cls_obj,mthd)
118
 			if not mthd in called:
90
 			if not mthd in called:
119
-				# print(cls_obj,mthd)
120
 				called.add(mthd)
91
 				called.add(mthd)
121
 				await mthd(self,*args,**kwargs) 
92
 				await mthd(self,*args,**kwargs) 
122
 	async def disconnect(self, close_code):
93
 	async def disconnect(self, close_code):
123
 		await self.call_all_mro("ws_disconn",close_code)
94
 		await self.call_all_mro("ws_disconn",close_code)
124
 		await self.ws_disconn_once(close_code)	  
95
 		await self.ws_disconn_once(close_code)	  
125
-	async def websocket_connect_x(self, event):
126
-		await super().websocket_connect(event)
127
-		print("<MRO")
128
-		print(type(self))
129
-		await self.call_all_mro("ws_conn",event)
130
-		await self.call_all_mro("ws_conn2",event)
131
-		print("/MRO>")
132
-		await self.ws_conn_once(event)
133
 
96
 
134
 class AclTaskMixin:
97
 class AclTaskMixin:
135
 	async def ws_disconn(self,*a,**kw):
98
 	async def ws_disconn(self,*a,**kw):
136
-		# for group in self.groups_set:
137
 		pass
99
 		pass
138
 
100
 
139
 	async def ws_conn0(self):
101
 	async def ws_conn0(self):
141
 		if glob_cl.has_cl:
103
 		if glob_cl.has_cl:
142
 			return
104
 			return
143
 		glob_cl.has_cl = True
105
 		glob_cl.has_cl = True
144
-		print("AclTaskMixin:ws_conn0")
145
 		glob_cl.run_persistent_loop(self)
106
 		glob_cl.run_persistent_loop(self)
146
 		glob_cl.acl = self.channel_layer
107
 		glob_cl.acl = self.channel_layer
147
-		# print("++++++++++++++++++++++++++")
148
-	async def ws_conn_once(self,*a,**kw):
149
-		pass
150
-		# print("\t\tws_conn_once:","AclTaskMixin")
108
+
151
 
109
 
152
 
110
 
153
 
111
 
176
 Mixins.AclTaskMixin = AclTaskMixin
134
 Mixins.AclTaskMixin = AclTaskMixin
177
 
135
 
178
 
136
 
179
-# GCLMixin
180
 class globCL(GCLMixin):
137
 class globCL(GCLMixin):
181
 
138
 
182
 	def __init__(self,*a,**kw):
139
 	def __init__(self,*a,**kw):
183
 		# for now we are not going to do any weird class stuff
140
 		# for now we are not going to do any weird class stuff
184
 		self.acl = None
141
 		self.acl = None
185
-		self.has_cl = False
186
-		# rconns = connect_redis()
187
-		self.rconn1 = connect_redis1()
142
+		self.has_cl = False		self.rconn1 = connect_redis1()
188
 		self.rconn = connect_redis()
143
 		self.rconn = connect_redis()
189
 		self.rman = RldMan()
144
 		self.rman = RldMan()
190
 		self.cbs_once = []
145
 		self.cbs_once = []
209
 								await v({k,self})
164
 								await v({k,self})
210
 							else:
165
 							else:
211
 								v({k,self})
166
 								v({k,self})
212
-
213
 						else:
167
 						else:
214
 							pass
168
 							pass
215
-						# p(k,v)
216
-
217
-						pass
218
 					except Exception as e:
169
 					except Exception as e:
219
 						p("persistent_fast_cb_loop Exception cbs_once:",e)
170
 						p("persistent_fast_cb_loop Exception cbs_once:",e)
220
 						p(flush=True)
171
 						p(flush=True)
221
-						# raise
222
 					else:
172
 					else:
223
 						pass
173
 						pass
224
 					finally:
174
 					finally:
227
 			await asyncio.sleep(self.fast_timeout)
177
 			await asyncio.sleep(self.fast_timeout)
228
 	async def persistent_loop(self,*a,**kw):
178
 	async def persistent_loop(self,*a,**kw):
229
 		while 1:
179
 		while 1:
230
-			# p("PL:",time.time(),flush=1)
231
-			# await asyncio.sleep(5)
232
-			# for k,v in cls.cbs.items():
233
 			for k,v in [*self.cbs.items()]:
180
 			for k,v in [*self.cbs.items()]:
234
 				try:
181
 				try:
235
 					call_info = callable_helper(v)
182
 					call_info = callable_helper(v)
236
 					if (call_info["is_callable"]):
183
 					if (call_info["is_callable"]):
237
 						if call_info["is_coroutine"]:
184
 						if call_info["is_coroutine"]:
238
-							pass
239
 							await v({k,self})
185
 							await v({k,self})
240
 						else:
186
 						else:
241
 							v({k,self})
187
 							v({k,self})
242
-
243
 					else:
188
 					else:
244
 						pass
189
 						pass
245
-					# p(k,v)
246
-
247
 					pass
190
 					pass
248
 				except Exception as e:
191
 				except Exception as e:
249
 					p("persistent_loop Exception",e)
192
 					p("persistent_loop Exception",e)
250
 					p(flush=True)
193
 					p(flush=True)
251
-					# raise
252
 				else:
194
 				else:
253
 					pass
195
 					pass
254
 				finally:
196
 				finally:
255
 					pass
197
 					pass
256
-			# cbs_once
257
 			cbs_once = [*self.cbs_once,*self.cbs_once_set]
198
 			cbs_once = [*self.cbs_once,*self.cbs_once_set]
258
 			self.cbs_once = []
199
 			self.cbs_once = []
259
 			self.cbs_once_set = set()
200
 			self.cbs_once_set = set()
270
 
211
 
271
 					else:
212
 					else:
272
 						pass
213
 						pass
273
-					# p(k,v)
274
-
275
-					pass
276
 				except Exception as e:
214
 				except Exception as e:
277
 					p("persistent_loop Exception cbs_once:",e)
215
 					p("persistent_loop Exception cbs_once:",e)
278
 					p(flush=True)
216
 					p(flush=True)
279
-					# raise
280
 				else:
217
 				else:
281
 					pass
218
 					pass
282
 				finally:
219
 				finally:
332
 		# "dflt_scope":{"globals":globals(),"locals":{}}
269
 		# "dflt_scope":{"globals":globals(),"locals":{}}
333
 		}
270
 		}
334
 		self.scopes['current_scope'] = self.scopes['dflt_scope_zloc']
271
 		self.scopes['current_scope'] = self.scopes['dflt_scope_zloc']
335
-		# self.scope_opt = "locals"
272
+		# self.scope_opt = ""locals
336
 		self.scope_opt = "globals"
273
 		self.scope_opt = "globals"
337
 		self.print_tb = 0
274
 		self.print_tb = 0
338
 
275
 
418
 						traceback.print_tb(e.__traceback__,file=sys.stdout)
355
 						traceback.print_tb(e.__traceback__,file=sys.stdout)
419
 				else:
356
 				else:
420
 					pass
357
 					pass
421
-					# print("ELSE")
422
 				finally:
358
 				finally:
423
-					# print("FINALLY")
424
 					pass
359
 					pass
425
 				print(end="",flush=True)
360
 				print(end="",flush=True)
426
 		return ret
361
 		return ret
427
 
362
 
428
 
363
 
429
 	def rld_files(self):
364
 	def rld_files(self):
430
-		# p()
431
-
432
 		ret = {
365
 		ret = {
433
 		"errs":{},
366
 		"errs":{},
434
 		"all":{},
367
 		"all":{},
435
 		"alle":{},
368
 		"alle":{},
436
 		}
369
 		}
437
-		
438
-
439
-
440
-		# for k in self.files:
441
 		for k in [*self.files]:
370
 		for k in [*self.files]:
442
 			self.rld_file(k,ret)
371
 			self.rld_file(k,ret)
443
-		# p("rld_files!")
444
 		p("",end="",flush=True)
372
 		p("",end="",flush=True)
445
 		return ret
373
 		return ret
446
 
374
 
447
 def fn1(*a,**kw):
375
 def fn1(*a,**kw):
448
-	# rld_files
449
 	glob_cl.rman.rld_files()
376
 	glob_cl.rman.rld_files()
450
 glob_cl =  globCL()
377
 glob_cl =  globCL()
451
 
378
 
453
 glob_cl.rman.rld_files()
380
 glob_cl.rman.rld_files()
454
 
381
 
455
 
382
 
456
-
457
-
458
-# print("..",end="\n",flush=True)
459
-
460
-
461
-r"""
462
-
463
-def atexit_fn():
464
-	pass
465
-	# rconn.flushall()
466
-	print("ATEXIT FN")
467
-	rinfo_len()
468
-	keys = rconn.keys()
469
-	print(keys)
470
-	print(len(keys))
471
-	print("t 000")
472
-	# time.sleep(10)
473
-	print("t 010")
474
-	# time.sleep(20)
475
-	print("t 020")
476
-	print("ATEXIT FN...")
477
-	rconn.flushall()
478
-atexit.register(atexit_fn)
479
-
480
-
481
-
482
-# """
483
-
484
-
485
 def atexit_fn():
383
 def atexit_fn():
486
 	print("atexit_fn!\n\n")
384
 	print("atexit_fn!\n\n")
487
 	rconn = glob_cl.rconn
385
 	rconn = glob_cl.rconn

Loading…
Cancel
Save