Running a background daemon in a flash application

So, I am creating a multi-user web application for internal use.

My goal is to create a flash application with a daemon process that starts when the server starts, which will update the global dictionary object.

I don’t necessarily have any sample code for publishing, since I tried to do it differently, and none of them were successful.

The daemon will create a thread pool (multiprocessing.Pool) to iterate over all database instances and run a couple of queries on them.

It seems that no matter how I try to implement this (right now, using the flash development server), it blocks the application and nothing can be done while it is running. I tried reading through a bunch of documentation, but as usual, a lot of other knowledge is assumed, and I'm ultimately overloaded.

I am wondering if anyone can offer some kind of guidance, even if it fits, I can find it because I was looking for everything for the "flash launch routine" and the like, but did not find anything useful. It seems that when I deploy this to our server, I can define some startup daemons in my .wsgi file, but is there still a way to do this locally? Is this even the right approach when I put it forward for general use?

Otherwise, I was just thinking about setting up a cron job, which constantly runs a python script that executes the queries I need, and is unloaded onto an instance of MongoDB or something like that, so that clients can simply extract from this (like doing all the requests on the server side of the application, Flask simply blocks the server, so nothing can be done with it - aka: cannot take measures regarding information, kill spids, etc.)

Any help with this will help to a large extent, my brain is spinning for several days.

from flask import Flask
from celery import Celery

app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'amqp://guest@localhost//'
app.config['CELERY_RESULT_BACKEND'] = 'amqp://guest@localhost//'

celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)

output = 0

@app.before_first_request
def init():
    task = my_task.apply_async()

@app.route('/')
def hello_world():
    global output
    return 'Hello World! - ' + str(output)


@celery.task
def my_task():
    global output
    result = 0
    for i in range(100):
        result += i
        output = result




if __name__ == '__main__':
    app.run()
+4
source share
2 answers

, , . - GIL , (, ) . - , GIL, , - (, ). . 2. :

import threading
import time
import random
from flask import Flask

app = Flask(__name__)

data_store = {'a': 1}
def interval_query():
    while True:
        time.sleep(1)
        vals = {'a': random.randint(0,100)}
        data_store.update(vals)

thread = threading.Thread(name='interval_query', target=interval_query)
thread.setDaemon(True)
thread.start()

@app.route('/')
def hello_world():
    return str(data_store['a'])

if __name__ == "__main__":
    app.run()
+2

All Articles