RODY/app/configs/global_var.py

43 lines
885 B
Python
Raw Normal View History

2022-11-15 17:59:06 +08:00
"""
@Time 2022/11/15 10:13
@Auth
@File global_var.py
@IDE PyCharm
@MottoABC(Always Be Coding)
@Desc
"""
2022-11-24 10:13:00 +08:00
import multiprocessing
2022-11-24 10:45:05 +08:00
global active_connections
global active_connections_dist
2022-11-15 17:59:06 +08:00
def _init(): # 初始化
2022-11-24 10:11:57 +08:00
# 中断标志
2022-11-15 17:59:06 +08:00
global _global_dict
_global_dict = {}
2022-11-24 10:11:57 +08:00
# ws列表存储
active_connections = multiprocessing.Manager().list()
# ws字典存储
active_connections_dist = multiprocessing.Manager().dict()
2022-11-15 17:59:06 +08:00
2022-11-24 10:45:05 +08:00
def get_active_connections():
return active_connections
def get_active_connections_dist():
return active_connections_dist
2022-11-15 17:59:06 +08:00
def set_value(key, value):
# 定义一个全局变量
_global_dict[key] = value
def get_value(key):
# 获得一个全局变量,不存在则提示读取对应变量失败
try:
return _global_dict[key]
except:
print('读取' + key + '失败\r\n')