[Twisted-Python] Is there a 'development mode ' for twisted ?

Laurens Van Houtven _ at lvh.io
Thu Sep 5 01:24:04 MDT 2013


On Thu, Sep 5, 2013 at 1:54 AM, a qi <free4machine at gmail.com> wrote:

> HI, there
>
>      I'm new to twisted,  after  reading the documents from twisted
> websites,  I got some questions:
>
>      1. Is there a 'development mode ' for twisted ?   like django, you
> can see your changes without restarting  server.
>

Not by default, but using the python project "watchdog" it's not very hard
to set up. Personally, I get it to run my *tests*, not my server, since I
really don't care about one particular piece of behavior my server has
right now which I am manually testing, but I care a lot about all of the
behavior my code has that I can automatically test.


>      2. Can I use django and twisted together?  actually, I want to use
> django's ORM   inside twisted server, so that I  can  manipulate  data
> easily.  I've try  'sob.py', but I can not figure it out how to use it .
>          On the other hand,   django is synchronous,  twisted is
> asynchronous, how to use them together if we can ?
>

That depends what you mean by mixing! FWIW, I hope to give a talk on this
subject at PyCon 2014. You can get the preliminary slides here:

http://blog.lvh.io/TwistedMixing/

as well as code examples:

http://www.github.com/lvh/TwistedMixing

Anyway, using Twisted to serve Django is really easy. Using the Django ORM
inside otherwise Twisted code is a *bit* trickier, since, as you mentioned,
it's blocking. There are two solutions to this, but neither is great:

- You can run calls to the Django ORM with deferToThread so that they block
somewhere else, but IIUC there are plenty of things that aren't really
calls (say, attribute access) that will still result in database IO ->
blocking
- Suppose you could get a green (as in gevent) Django ORM, you can use that
+ geventreactor, but that's gross and hacky

     3. How to suppress  logs that I do not need ?   there are many logs in
> twisted.log file,  as shown in the follow:
>
> 2013-09-05 07:04:07+0800 [SSHChannel session (0) on SSHService
> ssh-connection on ClientCommandTransport,client] remote eof
> 2013-09-05 07:04:07+0800 [SSHChannel session (0) on SSHService
> ssh-connection on ClientCommandTransport,client] unhandled request for
>

You could try filtering the log. That way you still get the loud logs if
you later need them for forensics, but you don't have to look at them right
now.

cheers
lvh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20130905/39bf01b1/attachment-0002.html>


More information about the Twisted-Python mailing list