ddollar / foreman

Manage Procfile-based applications

Home Page:http://ddollar.github.com/foreman

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Procfile for FLASK

VibhavKapadia96 opened this issue · comments

me@cpsc-vm:~/Desktop/minitwit$ foreman start -c worker=2
22:48:37 worker.1 | started with pid 3067
22:48:37 worker.2 | started with pid 3068
22:48:38 worker.1 | * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
22:48:38 worker.2 | * Serving Flask app "minitwit"
22:48:38 worker.2 | Traceback (most recent call last):
22:48:38 worker.2 | File "/usr/local/bin/flask", line 11, in
22:48:38 worker.2 | sys.exit(main())
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 513, in main
22:48:38 worker.2 | cli.main(args=args, prog_name=name)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 380, in main
22:48:38 worker.2 | return AppGroup.main(self, *args, **kwargs)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
22:48:38 worker.2 | rv = self.invoke(ctx)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
22:48:38 worker.2 | return _process_result(sub_ctx.command.invoke(sub_ctx))
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
22:48:38 worker.2 | return ctx.invoke(self.callback, **ctx.params)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
22:48:38 worker.2 | return callback(*args, **kwargs)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 64, in new_func
22:48:38 worker.2 | return ctx.invoke(f, obj, *args[1:], **kwargs)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
22:48:38 worker.2 | return callback(*args, **kwargs)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 438, in run_command
22:48:38 worker.2 | use_debugger=debugger, threaded=with_threads)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 814, in run_simple
22:48:38 worker.2 | inner()
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 774, in inner
22:48:38 worker.2 | fd=fd)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 666, in make_server
22:48:38 worker.2 | passthrough_errors, ssl_context, fd=fd)
22:48:38 worker.2 | File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 577, in init
22:48:38 worker.2 | self.address_family), handler)
22:48:38 worker.2 | File "/usr/lib/python2.7/SocketServer.py", line 417, in init
22:48:38 worker.2 | self.server_bind()
22:48:38 worker.2 | File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
22:48:38 worker.2 | SocketServer.TCPServer.server_bind(self)
22:48:38 worker.2 | File "/usr/lib/python2.7/SocketServer.py", line 431, in server_bind
22:48:38 worker.2 | self.socket.bind(self.server_address)
22:48:38 worker.2 | File "/usr/lib/python2.7/socket.py", line 228, in meth
22:48:38 worker.2 | return getattr(self._sock,name)(*args)
22:48:38 worker.2 | socket.error: [Errno 98] Address already in use
22:48:38 worker.2 | exited with code 1
22:48:38 system | sending SIGTERM to all processes
22:48:38 worker.1 | terminated by SIGTERM

I want to run flask app with concurrency of 2

And here is my procfile

worker: flask run

It seems that Foreman starts your flask app two times, with the same settings. Port 5000.

This leads to the second process exiting with an "Address already in use" error.

My take: This is not a bug in foreman, it's how the Flask app is configured.

Here are some other Flask-related links, which I found for you.

Blog Post explaining how to set which port to use in an app

Snippet which extends a Flask app with option-reading from the command-line

An app skeleton which uses environment variables to pick PORT

Can this be closed, now?

@VibhavKapadia96 Is this still an issue?

I am not sure with -c, but with -m. I managed to get the ports running on separate ports by running:
flask run -p $PORT
Where $PORT is set by foreman, and it will increment the port automatically for you.

I had ran foreman start --formation app1=3,app2=3,app3=3 And it created all the instances with their own ports, starting at 5000. And for each application, the port is incremented by +100.

http://ddollar.github.io/foreman/#PROCFILE Hopefully this helps!