从ini文件中读取参数,每X秒刷新共享内存

读取参数,每X秒刷新共享内存

def batch_job_004():
if_batch_start = utility.get_myibs_ini(“batch”, “batch_job_004_start”)
batch_start_date = utility.get_myibs_ini(“batch”, “batch_job_004_start_date”)
batch_start_time = utility.get_myibs_ini(“batch”, “batch_job_004_start_time”)
batch_job_internal_time = utility.get_myibs_ini(“batch”, “batch_job_004_internal_time”)
batch_job_started = utility.get_myibs_ini(“batch”, “batch_job_004_status”)

###########################
# scheduled job start here
###########################
conf = configparser.ConfigParser()
logger.info("Loading configuration...")
conf.read(myibs_ini)

rtn_str = None

import mmap
import contextlib

utility.set_myibs_ini("batch", "batch_job_004_status", "STARTED")
with contextlib.closing(mmap.mmap(-1, 1024*1024, tagname="myibs.ini", access=mmap.ACCESS_WRITE)) as m:
    sections = conf.sections()
    dict_myibs_ini = {}

    dict_sections = {}
    for section in sections:

        items = conf.items(section)
        dict_items = {}
        for item in items:
            in_parm_tagname = "myibs.ini" + ":" + section + ":" + item[0] + "=" + item[1]
            logger.info(in_parm_tagname)
            print(in_parm_tagname)

            dict_items[item[0]] = item[1]
            #print(dict_items)
            dict_sections[section] = dict_items
            #print(dict_sections)

    import json
    obj_json = json.dumps(dict_sections)
    print("dict->json", obj_json)

    try:
        m.seek(0)
        m.write(str(obj_json).encode())
        m.flush()
        rtn_str = "000000"
    except Exception as e:
        rtn_code = None
        logger.error(e)
        print(e)

    logger.info("Configuration loaded.")
    #time.sleep(100000)
    print(obj_json)
    return rtn_str
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值