Is there any "remote console" for twisted server? - python

I am developing a twisted server. I need to control the memory usage. It is not a good idea to modify code, insert some memory logging command and restart the server. I think it is better to use a "remote console", so that I can type heapy command and see the response from the server directly. All I need is a remote console, I can build one by myself, but I don't like to rebuild a wheel. My question is: is there already any remote console for twisted?
Thanks.

twisted.manhole.telnet uses the deprecated module twisted.protocols.telnet. It is recommended to use twisted.conch.manhole instead.
Here are some tutorials of how to use it:
Writing a client with Twisted.Conch -- twisted.conch documentation
Network programming with the Twisted framework, Part 4 -- IBM developerWorks
Twisted Network Programming Essentials - Chapter 10 -- Online book preview

Take a look at twisted.manhole

Related

pydev debugger usage as a python module

pydev debugger is a python debugger used by pydev and pycharm. It seems much more powerful than pdb. Its code is available (https://github.com/fabioz/PyDev.Debugger), and it is easy to install through pip. The package name is pydevd.
However, there is no information on how to use it from python code (outside of pydev or pycharm IDE). The documentation is completely lacking.
Does anyone know how to use it? I would like to do something like that:
import pydevd
pdd = pydevd.debug("python myscript.py")
pdd.set_break_point(file="myscript.py", lineno=12)
pdd.start()
pdd.read_variable("a")
pdd.continue()
well, I agree that the docs are lacking, but the idea is mostly that you'd use it from within the IDE, not programmatically.
The only public API you should use programmaticallyis pydevd.settrace(), which is the API which will setup a breakpoint at the place it's put programmatically (meaning the debugger will stop at that line -- the same effect of having pdb.set_trace() -- and that same API will also connect to the frontend for remote debugging if it's still not connected (i.e.: http://www.pydev.org/manual_adv_remote_debugger.html -- code: https://github.com/fabioz/PyDev.Debugger/blob/a4a58179dab9f9fb93559066f0ef22ac59c59e04/pydevd.py#L1065).
Now, currently the only frontends are PyDev and PyCharm, there's no frontend that gives you a command line... the whole communication happens by connecting to a thread in the debugger backend through a socket (again, there are no real docs, but the code should be easy to read on what the socket accepts and the protocol is pretty simple: https://github.com/fabioz/PyDev.Debugger/blob/a4a58179dab9f9fb93559066f0ef22ac59c59e04/_pydevd_bundle/pydevd_process_net_command.py).
There are unit-tests in pure-python code which exercise that (i.e.: connect to a debugger, and issue commands through sockets -- https://github.com/fabioz/PyDev.Debugger/blob/a4a58179dab9f9fb93559066f0ef22ac59c59e04/tests_python/debugger_unittest.py), so, it shouldn't be that hard to actually do a command-line frontend to it -- it's just that no one had interest on it until now, but if someone would like to contribute a command-line frontend to PyDev.Debugger, it'd be welcome ;)

Writing browser-based MMO server in Python

I want to write a server for a browser-based MMO game, which uses WebSocket for communication, SQL Server for database, and the language of choice for server is Python. What I would like to know is which libraries can provide Websocket and MMO support, and should I use Stackless or PyPy?
ws4py is a websocket library for python 2.6 and 2.7, and this is the customized django-websocket applied for rfc6455. Websocket became RFC6455 in the end of last year, so you should use libraries applied for it. These both libraries are supporting it.
ps Tornado is also supporting RFC6455 from version2.2.
Take a look at Tornado. It should contain all the stuff you need.
Tornado is definitely a good choice for what you are doing. It supports web sockets with the latest version and it works fine with PyPy if you are concerned about performance. I already have a prototype MMO working with this set up and it works great. Also you can add new connection types later. So you could start with web sockets, but if you ported the game client to a mobile device you can add a TCP handler into the game with minimal effort.
On the database side, I would consider looking around at other options. Maybe SQL Server is perfect for your needs, but I am more inclined to use something like Membase (renamed Couchbase recently) if you can do without the database being relational. Only because it scales well and seems to be very efficient on cloud hardware.
Good luck with your endeavour.

Suggest a standalone python web framework?

I have a python program that I would like to present as a simple web application. The program currently uses sqlite for storage. I also need to distribute the whole thing to colleagues so having something standalone and easy to start would be ideal ( no install if possible). This web app is meant to be used locally , not by multiple users over a network.
Is there a suitable python framework that might fit my needs? I looked at Django so far but it seems a bit heavy handed for what I need.
Thanks for any suggestions.
I have never tried it myself, but you could try Bottle:
Bottle is a fast, simple and lightweight WSGI micro web-framework for
Python. It is distributed as a single file module and has no
dependencies other than the Python Standard Library.
try http://docs.python.org/library/simplehttpserver.html
As web frameworks are not part of the standard lib, you will have to install something in every case. I would propse to look at http://flask.pocoo.org/. It has a build in WSGI server.
Lots of choices for Python web frameworks! Another is web2py which is designed to work out of the box and allows, but doesn't require, through-the-web development. It is mature and has a strong community and is well-documented.
Tornado as a framework may be a lot more than what you're looking for. However it will meet the requirement of being a completely python based web server. http://tornadoweb.org
I generally just download the source, drop it in /tornado/ of my project and do includes there from the app.
I don't think that any web framework is specifically oriented for the use case you're talking about; They all assume they are running on a server and there's a browser on a remote machine that is accessing them.
A better approach is to think about the HTTP server you'll be using. It's probably preferable to use a server that's as easy to pack and ship as the rest of the python code you'll be using. Now most frameworks provide a 'development' server that's easy to invoke from the command line, but most of them are intended to be "easy for the developer" which often means they are restricted to a single thread. This is bad for deployment because single threaded servers will always feel a bit sluggish.
CherryPy stands out in contrast, by providing a full featured, embedded server that's easy to configure for many use cases, and is available by default with the rest of the framework. There are probably others, but I haven't used 'em.

How to run python scripts?

I am a PHP developer and am I want to use python for a project. What is the most common and simplest way to run python script on a server like apache or lighttpd? I am having trouble understanding how server languages that are not PHP or ASP run on servers.
In Python we have something called WSGI. But I believe this is too much for you right now. Grab a Python web framework, like Django. It comes with a web server and with good documentation on how to deploy it later. Play with it and things will start to clear up.
The longer version is that Python is a general purpose language - it's not designed for the web like PHP is. So you need a bit of work the get it to do web stuff and we already have some good frameworks for that (Django is the easiest to start with, so that is why I'm recommending it to you).
In general you should understand how the web works. It uses HTTP as a protocol for communication, which is build on top of the TCP stack, so a web application is just a server, that uses sockets (PHP has them as well as Python) and understands HTTP. Python comes with one build in - the SimpleHTTPServer, but it is not very good for production uses (it's great for development, though). This is why there are things like mod_wsgi (Python specific), FastCGI (general purpouse). Those things are basically ways for a real, production grade, web server (Apache, nginx) to talk to our python app and feed it the HTTP they get.
You can install gunicorn a Pure Python WSGI HTTP Server for UNIX. http://gunicorn.org/.
Typically, Apache is used with mod_python. See this mod_python tutorial

For anyone with free time: Trying to learn how to replace PHP with Python, failing terribly [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Python noob here: On a Python enabled web server, how do I use Python?
I want give web development using Python a shot, but I'm failing hard. I don't even know if I CAN run Python. The webpage for my web host says it supports all kinds of stuff, including Python. I've never touched anything CGI related and this does not appear to be a noob friendly area.
Below is all the information I could think of that might be useful:
Shared host: Yes
Webhost: dibbsonhosting.com
Server OS: linux
Python installed: Yes (or so says the webhost)
mod_python installed: Don't Know
WSGI installed: Don't Know
Access to http.conf: No
Terminal access: No
Cpanel: Yes
FTP: Yes
Django: downloaded latest stable release, not uploaded anywhere, not
sure where to put it.
DB: MySQL 5.x
I really want to use Python for web development! Thanks!
Alright, I'm not going to hold your hand, but let me suggest:
Start off by installing and running it on your own computer, if at all possible. This lets you see what you can do with Python before you have to worry about the complexities of setting it up with a webserver.
If you've never used Python before, then before you start trying to use it for web development, take a few minutes getting the feel of it: what function definitions look like, the abilities of slicing, the neatest way to do loops, and so on. There are various good tutorials available: Dive into Python claims to be aimed at people with experience programming in other languages.
Start learning with a microframework, rather than Django. When you want to do serious websites, you can take advantage of the power of Django, but for now, keep it straightforward. As was suggested in your other question, Flask and Bottle are good contenders.
MALON,
Django has a builtin development server; try it on your local machine first.
The Django tutorial seems to assume that you are running some Unix flavor (like Linux) on your local machine (a Mac would be fine too). If you are running some MS Windows, this page may help. Don't be scared of the command line, setup is only once.
The Django admin app is worth the trouble!
Indeed PHP is synonimous of cheap hosting and very well supported. Write some crap and run. Python support is not as pervasive; at some hosting providers, working with Python is almost as easy as with PHP, and most have instructions about Django in their FAQs.
The mechanics is different: Python frameworks don't reload with each page load like PHP, there is an application always running that responds to HTTP requests. That is why you are advised to start on your local machine, just to acquaint the new paradigm.

Categories