Fedora Account System
Red Hat Associate
Red Hat Customer
Description of problem: I am trying to start a new python 3.3 app on Openshift. Due to the changes they made a couple of weeks ago I am having trouble getting the new app started. I copied a known working app into a new Python 3.3 Openshift app. I am now getting this error: Target WSGI script '/var/lib/openshift//app-root/runtime/repo/wsgi.py' does not contain WSGI application 'application'. My wsgi.py code is the same in both working and non working apps It seems there is an existing httpd server running already when the wsgi.py entry point is executed. I also noticed the entry point is an 'application' function inside wsgi.py and not wsgi.py itself like it used to be. When using the exact same code as an other working Openshift app I get this error: 'wsgi.py' does not contain WSGI application 'application' The code that I use to start my app that I have always used cans be seen below. The app that does work with the same code was created before the March 14 changes. Is this a bug or a fundamental change in how Openshift now does things? How do I start my server (waitress, cherrpy, simple, etc) now? import os from myapp import main_production_no_pserve if __name__ == '__main__': ip = os.environ['OPENSHIFT_PYTHON_IP'] port = int(os.environ['OPENSHIFT_PYTHON_PORT']) app = main_production_no_pserve(global_config=None) from waitress import serve print("Starting Waitress Server on http://{0}:{1}".format(ip, port)) serve(app, host=ip, port=port, threads=50) Version-Release number of selected component (if applicable): How reproducible: Create a Openshift python 3.3 app. How do I start my server (waitress, cherrpy, simple, etc) now? Steps to Reproduce: 1. 2. 3. Actual results: 'wsgi.py' does not contain WSGI application 'application' Expected results: My server starts from the above code. Additional info: Since the March 14 changes I was able to change my existing openshift apps (app.py to wsgi.py) to the new method and they work. Create new Openshift apps have the problem.
> Target WSGI script '/var/lib/openshift//app-root/runtime/repo/wsgi.py' does not contain WSGI application 'application'. This error message points to missing 'application' function - simple example follows: > def application(environ, start_response): > status = '200 OK' > output = 'Hello World!' > > response_headers = [('Content-type', 'text/plain'), > ('Content-Length', str(len(output)))] > start_response(status, response_headers) > > return [output] Did you look at the default wsgi.py file provided by OpenShift? https://github.com/openshift/origin-server/blob/master/cartridges/openshift-origin-cartridge-python/usr/versions/3.3-scl/template/wsgi.py
> Address already in use - Cannot start own server because an httpd instance already exists I think you're trying to bind to the wrong port that is already owned by httpd/mod_wsgi to serve your WSGI application. Take a look at https://github.com/openshift/origin-server/blob/master/cartridges/openshift-origin-cartridge-python/usr/versions/3.3-scl/template/wsgi.py code again and you'd see: > httpd = make_server('localhost', 8051, application) I think you might want to bind your waitress/cherrypy/simple server to this localhost:8051 port as well. Closing NOTABUG. Please, feel free to reopen if you still think this is a bug or regression. Thank you for the bug report.
I have looked at your example code and have changed mine to the below code. However, if __name__ == '__main__': code never gets run like in the old Openshift method. The new method seems to target the function 'application' in wsgi.py as an entry point instead of wsgi.py itself. I tried the following but I am now getting PermissionError: [Errno 13] Permission denied Can you give an example on how to start a 'waitress' server using the new methodology? I am obviously missing something :) def application(environ, start_response): from waitress import serve from myapp import main_production ip = 'localhost' port = 8051 app = main_production(global_config=None) serve(app, host=ip, port=port, threads=50) return if __name__ == '__main__': from waitress import serve from myapp import main_production ip = 'localhost' port = 8051 app = main_production(global_config=None) serve(app, host=ip, port=port, threads=50)
@fatfantasma I think stackoverflow.com would be better place to ask questions like in comment 3, as bugzilla is not a support tool. I'll get back to you once I have some spare time to investigate this.
I agree with you that stackoverflow.com is a better place. However, nobody answers there. In fact, I have been redirected here a couple of times which I find ridiculous but I have been force to on this occasion. I would appreciate it greatly if you can give me an example how to start a server using the new methodology. :) I will even post the answer in stackoverflow for the next poor bastard as not to bother you again:)
Created attachment 882723 [details] Python 3.3 - app.py How to test: Put this file into the git repository, while still having wsgi.py from the default template repository. Expected results: 'app.py' server is running instead of Apache/mod_WSGI.
@fatfantasma, read through the example 'app.py' file provided in Comment 6. The example file can run gevent/cherrypy/flask servers. It's just up to what you put into the dependencies/requirements of your app.
For QE: See Comment 6 to see how to test this.
Further steps (as seen from Bug 1082363 Comment 14): 1. Create Python 3.3 app $ rhc app-create py33 python-3.3 > .. > Creating application 'py33' ... done > Your application 'py33' is now available. > .. # git push something to see the remote messages $ cd py33 && touch README && git add README && git commit -amREADME && git push > remote: Running setup.py script.. > ... > remote: Starting Python 3.3 cartridge (Apache+mod_wsgi) > remote: Application directory "/" selected as DocumentRoot > remote: Application "wsgi.py" selected as default WSGI entry point 2. Check the app from the Web Working template "Welcome to Openshift" appeared, meaning that Apache/mod_WSGI successfully loaded the default 'wsgi.py' file. $ rhc ssh py33 $ ps aux > Listed processes (snip): > /usr/sbin/httpd > /usr/sbin/rotatelogs 3. Add 'app.py' file to the application: - The 'app.py' file to be attached below. - Note that 'app.py' is still undocumented feature that came from Python 3.3 community cartridge. We'll eventually support it officially, see https://trello.com/c/5qhdqEuk. $ git add app.py && git commit -am"Adding app.py" && git push > remote: Stopping Python 3.3 cartridge > remote: Running setup.py script.. > remote: Starting Python 3.3 cartridge (app.py server) 4. Check the app from the Web Working template "Welcome to Openshift" appeared, meaning that app.py server was successfully started and loaded the 'wsgi.py' file. $ rhc ssh py33 $ ps aux > Listed processes (snip): > python -u app.py
Created attachment 882741 [details] Python 2.6/2.7 - app.py Attaching 'app.py' also for Python 2.6 and 2.7.
fatfantasma 2014-04-04 20:05:02 CEST @Vojtech Here are the steps to reproduce OSError: [Errno 98] Address already in use. 1. Create python 3.3 app 2. Clone app to PC 3. Delete wsgi.py 4. Add in my app.py 5. commit and push At this point you will get the error or not depending if the server is running before. If not error. Just make another commit and push. The error is Traceback (most recent call last): File "app.py", line 299, in <module> server = make_server(ip, port, application) #Serve from our local server File "/opt/rh/python33/root/usr/lib64/python3.3/wsgiref/simple_server.py", line 146, in make_server server = server_class((host, port), handler_class) File "/opt/rh/python33/root/usr/lib64/python3.3/socketserver.py", line 430, in __init__ self.server_bind() File "/opt/rh/python33/root/usr/lib64/python3.3/wsgiref/simple_server.py", line 50, in server_bind HTTPServer.server_bind(self) File "/opt/rh/python33/root/usr/lib64/python3.3/http/server.py", line 135, in server_bind socketserver.TCPServer.server_bind(self) File "/opt/rh/python33/root/usr/lib64/python3.3/socketserver.py", line 441, in server_bind self.socket.bind(self.server_address) OSError: [Errno 98] Address already in use At this point if you do a "rhc app-force-stop <app>" and do another commit and push the app will run correctly. This must be done for every new commit and push or you will get the error.
@fatfantasma, can you ssh into your gear and run `ps aux'? What's the output? What ip/port are you trying to bind to?
Did you run through my steps to replicate the error? If you look at my app.py you clearly see what ports I am binding to: if __name__ == '__main__': ip = os.environ['OPENSHIFT_PYTHON_IP'] port = int(os.environ['OPENSHIFT_PYTHON_PORT']) server = make_server(ip, port, application) server.serve_forever() REMEMBER!!! the above code works as long as you do a 'rhc app-force-stop' before you push. This problem occurred after the March 14 update. After I get the OSError: [Errno 98] Address already in use I ssh into my app and did the 'ps aux' command. The output is as follows: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 6631 249351 0.0 0.1 94472 12648 ? S 13:57 0:02 python -u app. 6631 270783 0.0 0.0 104920 2676 ? S 17:23 0:00 sshd: 533ee784 6631 270786 0.0 0.0 4108 576 pts/1 Ss+ 17:23 0:00 /usr/bin/tail 6631 277490 0.0 0.0 104920 2664 ? S 17:25 0:00 sshd: 533ee784 6631 277491 1.7 0.0 108740 2164 pts/2 Ss 17:25 0:00 /bin/bash --in 6631 278274 0.0 0.0 110240 1160 pts/2 R+ 17:26 0:00 ps aux
Also make sure you edit/push a couple of times. Check for the error after the push. You make think it works but it's really the old version running because the push never stop the old server.
Verified on STG(devenv-stage_783), cannot meet the same error by following steps in comment 6 and comment 11, the app main page displays well by using app.py no matter wsgi.py exists or not: 1. Create a python-3.3 app; 2. Delete wsgi.py; 3. Copy app.py(the one from @fatfantasma) to $app; 4. Push the changes; remote: Activating deployment remote: Starting Python 3.3 cartridge (app.py server) remote: ------------------------- remote: Git Post-Receive Result: success 5. SSH to the app [py33-domain2014.stg.rhcloud.com 53439d5cdbd93cb7b30008a6]\> ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 1884 476964 0.3 0.1 94468 12700 ? S 04:22 0:00 python -u app.py 1884 476965 0.0 0.0 11476 760 ? S 04:22 0:00 /bin/bash /var/lib/openshift/53439d5 1884 476966 0.0 0.0 197960 2532 ? Sl 04:22 0:00 /usr/bin/logshifter -tag python 1884 477285 0.0 0.0 104920 2684 ? S 04:23 0:00 sshd: 53439d5cdbd93cb7b30008a6@pts/0 1884 477298 0.8 0.0 108740 2280 pts/0 Ss 04:23 0:00 /bin/bash --init-file /usr/bin/rhcsh 1884 477582 0.0 0.0 110244 1144 pts/0 R+ 04:23 0:00 ps aux 6. Access the app URL, it displays "Welcome to your Python application on OpenShift"
Created attachment 883932 [details] Provided by fatfantasma
There is still a problem. I have a feeling you guys are not doing multiple pushes and verifying if the server actually gets stopped. That app WILL always appear to work since it's the original server that is still running when the app get originally created. I will try to be more specific on the step. 1. Create python 3.3 app online 2. Delete wsgi.py 3. Copy my app.py (provided above). 4. RHC tail <app name> 5. push changes (push will be SUCCESSFUL) 6. You should now see the Error 98 after push has finished and it tries to restart. 7. The app with the new changes fails to start BUT the old app is still running which gives the illusion that it work. I can do this every time. Other have the same error.
It looks like you guys fix it. Since there were no updates here for 6 days I tried to push again. It worked :) I do see a bunch of new messages (using tail) before the server starts so you guys must have been working on it.
@fatfantasma glad to hear this feedback from you. Thank you for your help!