0

I want to update a dictionary periodically in flask app.

My code is:

app.py

import gevent.monkey
gevent.monkey.patch_all()

from flask import Flask
from apscheduler.schedulers.background import BackgroundScheduler

app = Flask(__name__)

if __name__=='__main__':
  app.dictionary = { ... }
  app.scheduler = BackgroundScheduler(daemon=True)
  app.scheduler.add_job('updater:Updater.update', ... )
  app.scheduler.start()
  app.run(...)

updater.py

class Updater:
  @classmethod
  def update_dict(cls, old_dic, new_dic):
    old_dic = new_dic  # update

  @classmethod
  def update(cls, old_dic):

    # some business logic ..

    cls.update_dict(old_dic, new_dic)

Of course, it works if I manually modify the values ​​inside the dictionary (old_dic.update( ... ) or old_dic[..] = ... ), but it doesn't work if I bind the whole new dictionary (old_dic = new_dic).

Is there any way to directly access app.dictionary in Updater?

Thanks!

sjpark
  • 111
  • 9

0 Answers0