2021年1月5日星期二

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.

https://stackoverflow.com/questions/65590483/thread-safety-query-on-python-3-global-variable January 06, 2021 at 01:05PM

没有评论:

发表评论