Strange error when trying to get data from database in another file

Solution
while True:
    with app.app_context():
        c = Value.query.count()
    with app2.app_context:
        c2 = Value2.query.count()
    print(c, c2)
    time.sleep(1)