<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 5, 2013 at 1:54 AM, a qi <span dir="ltr"><<a href="mailto:free4machine@gmail.com" target="_blank">free4machine@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>HI, there<br><br></div>     I'm new to twisted,  after  reading the documents from twisted websites,  I got some questions:<br>

<br>     1. Is there a 'development mode ' for twisted ?   like django, you can see your changes without restarting  server.   <br></div></div></blockquote><div><br></div><div>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.<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div><div>     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 .   <br>


</div><div>         On the other hand,   django is synchronous,  twisted is asynchronous, how to use them together if we can ?<br></div></div></blockquote><div><br></div><div>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:<br>

<br><a href="http://blog.lvh.io/TwistedMixing/">http://blog.lvh.io/TwistedMixing/</a><br><br></div><div>as well as code examples:<br><br><a href="http://www.github.com/lvh/TwistedMixing">http://www.github.com/lvh/TwistedMixing</a><br>

<br></div><div>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:<br>

<br></div><div>- 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<br>

</div><div>- Suppose you could get a green (as in gevent) Django ORM, you can use that + geventreactor, but that's gross and hacky<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div dir="ltr"><div></div><div></div><div>     3. How to suppress  logs that I do not need ?   there are many logs in twisted.log file,  as shown in the follow:<br>
<br>2013-09-05 07:04:07+0800 [SSHChannel session (0) on SSHService ssh-connection on ClientCommandTransport,client] remote eof<br>2013-09-05
 07:04:07+0800 [SSHChannel session (0) on SSHService ssh-connection on 
ClientCommandTransport,client] unhandled request for <br></div></div></blockquote><div><br></div><div>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.<br>

<br></div><div>cheers<br>lvh<br></div></div></div></div>