Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Intro and question re Google App Engine and web stuff in Pythonista
-
@ronjeffries , I am not into the stuff you are talking about. But I would like to be, but still beyond me.
But I have been talking before how to have a local setup up before with bottle, a client and server for testing.
@omz also has another product called Editorial, which can also execute Python. So was able to start a bottle app in Editorial and send requests to it from Pythonista. There were also talks about using theads inside Pythonista to try to both at the same time. I think a difficult situation. Not saying you should buy Editorial, but is an interesting way to make a client/server test app.
But if you search the forum bottle and Editorial, I think you would get the discussion threads -
@ronjeffries , this is a good read about ruining bottle
https://forum.omz-software.com/topic/2451/running-bottle-in-pythonista-and-another-script-also -
Thanks @Phuket2 I'll check that out.
Here's my new problem, I have this code
# coding: utf-8 # example from https://docs.python.org/2/library/socketserver.html import SocketServer class MyTCPHandler(SocketServer.BaseRequestHandler): """ The request handler class for our server. It is instantiated once per connection to the server, and must override the handle() method to implement communication to the client. """ def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() print "ron jeffries has gotten something working part 2" print "{} wrote:".format(self.client_address[0]) print self.data # just send back the same data, but upper-cased back = "here you go\n" + self.data.upper() self.request.sendall(back) if __name__ == "__main__": HOST, PORT = "localhost", 9999 # Create the server, binding to localhost on port 9999 server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler) # Activate the server; this will keep running until you # interrupt the program with Ctrl-C server.serve_forever()
So when I run this code, the server is running, and if I go into Safari I can send like
localhost:9999/?add&key=k1&val=v1
And get back sensible stuff from my server. So my soon-to-be app engine code would be in the server above. Which means I need to stop it, modify it, start it up again, then test again on the Safari side.
box to stop the thing, edit it, and restart it, I get the message[Errno 48] Address already in use.
I can stop Pythonista and restart it to run again but that seems wrong. So how do I, within Pythonista, stop this server, edit it, and restart it on the same address?
Thanks!
-
@ronjeffries , as I say I can only talk about this subject in very very and very broad strokes. I have no chance to help on this on. Someone else will come along though that can.
-
@ronjeffries You can get rid of the error like this:
# ... if __name__ == "__main__": # Probably not strictly necessary: SocketServer.TCPServer.allow_reuse_address = True HOST, PORT = "localhost", 9999 # Create the server, binding to localhost on port 9999 server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler) # Activate the server; this will keep running until you # interrupt the program with Ctrl-C try: server.serve_forever() except KeyboardInterrupt: # Clean shutdown: server.shutdown() server.socket.close()
-
For some reason when I run a web server with Pythonista, stop it, then try to restart, I get the error message once, but the next time I run the script (without restarting Pythonista) it's gone and the server runs again. Don't ask me why that happens...
-
Thanks @omz, I'll try that ... in other news, how do i do a control-C in Pythonista? Thanks!
-
@omz Should
server.shutdown
beserver.shutdown()
? Not sure.@ronjeffries You can run two scripts at once using threads. Take a look at the
threading
module. Running something on a thread will not prevent you from using the interpreter or from performing other tasks while it runs. -
Tapping the "Stop" button is essentially the same as Ctrl+C.
Should server.shutdown be server.shutdown()? Not sure.
Yes, thanks.
-
Thanks @omz I had hoped that was the case.
Thanks @Webmaster4o maybe I'll have a look at that, though I am thinking that I need to go another way and maybe talk to the thing from Safari or something. Or maybe just work on the core in Pythonista and then do the real work with the App Engine launcher on the Mac.Thanks!
-
Another option to navigate to a page you have created is to use the webbrowser module, which will open the page in a separate tab inisde pythonista, which runs in its own thread.