[Flask] Issue with Daemonization, Flask, and Elastic Beanstalk

Tom Vaughan thomas.david.vaughan at gmail.com
Mon Apr 3 20:02:04 EDT 2017


The problem, as shown in the stacktrace in your original email, is
that you call exit in daemon.py in the child process.

If you want to keep this approach, you should use subprocess.Popen
instead of daemon.py to invoke process_text.py. Like:

    subprocess.Popen(["python", "process_text.py"])

See also: https://docs.python.org/3/library/subprocess.html#replacing-the-os-spawn-family

However, this has two problems. 1) process_text.py is passed data via
testfile.txt which is created in application.py. testfile.txt will be
overwritten each time the Flask app is called. When more than one
request is made at the same time testfile.txt will be overwritten at
the same time it is being processed by another request. At a minimum
each request should use a unique temporary file name. 2) If the Apache
worker process quits (most likely because it has served its limit of
requests) while there are still running jobs of process_text.py these
jobs will be killed.

I suggest you take a look at using at task queue like Celery instead.
http://www.celeryproject.org/ Redis could probably be made to work
too.

-Tom



On Mon, Apr 3, 2017 at 7:19 PM, Blythe Sheldon <blythe.sheldon at gmail.com> wrote:
> Hello— Here you go.
>
> https://gist.github.com/blythest/4b8afa1c73dd98457f0c8ef68e29bc6c/32ed1547f636abccafdf003d107b6f33fba5fba8
> https://gist.github.com/blythest/6cd30bc5fc5953739b6d763801d94e97
>
> Thanks,
> Blythe
>
> On Mon, Apr 3, 2017 at 2:59 PM, Blythe Sheldon <blythe.sheldon at gmail.com> wrote:
>> Here you go.
>>
>> Thanks,
>> B
>>
>> On Mon, Apr 3, 2017 at 2:45 PM, Jonathan Chen <tamasiaina at gmail.com> wrote:
>>> Is it possible to see application.py or daemon.py?
>>>
>>>
>>> ~Jonathan C.
>>>
>>> On Mon, Apr 3, 2017 at 2:22 PM, Blythe Sheldon <blythe.sheldon at gmail.com>
>>> wrote:
>>>>
>>>> Hello,
>>>>
>>>> I'm new to the list, so apologies if a question like mine has been
>>>> asked and answered before. I've created a Flask app that accepts text
>>>> input via a form, which then gets saved to the server and processed by
>>>> another script, which I've daemonized per my own scrappy daemon.py.
>>>> After deploying the app to AWS Elastic Beanstalk, I see that my text
>>>> processing script does not run. I don't have enough background with
>>>> mod_wsgi to know how to resolve this issue, and given the simplicity
>>>> of what I'm trying to accomplish, I want to use the most appropriate
>>>> daemonizing tool. I've attached the the error log output. If anyone
>>>> has any advice on how to fix this error, I'd appreciate it!
>>>>
>>>> Thanks,
>>>> Blythe
>>>>
>>>> _______________________________________________
>>>> Flask mailing list
>>>> Flask at python.org
>>>> https://mail.python.org/mailman/listinfo/flask
>>>>
>>>
>>>
>>> _______________________________________________
>>> Flask mailing list
>>> Flask at python.org
>>> https://mail.python.org/mailman/listinfo/flask
>>>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask


More information about the Flask mailing list