Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

thread safety query on python 3 global variable

I have a request_processor that processes web requests coming to my python webserver. However, this request_processor needs to be updated every x hours. I am using schedule library in python for the same. I want to make sure I am not leaving any holes that compromises thread safety. Please review the following approach that I am doing now which is completely without any locks.

request_processor: IRequestProcessor


def invoke(req):
    """ Entry point for web requests"""
    response = request_processor.process(req)
    ...


def init_processor():
    _request_processor = ... #S Setup request_processor
    global request_processor
    request_processor = _request_processor


def schedule_reload():
    schedule_model_reload = ContinuousScheduler()
    schedule_model_reload.every(SCHEDULE_MINS).minutes.do(init_processor)
    halt_schedule_flag = schedule_model_reload.run_continuously()


def server_startup():
    init_processor()
    schedule_reload()

Please review for thread safety issues in the above code. I am newbie to python programming. Thanks in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...