Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango project with twisted and run as "Daemon"
    primarykey
    data
    text
    <p>Last two day I'm trying to find a way to run a working django project under twisted. After detailed searching I found several methods to configure it. But most of them are deal with how to run the app via command line not as a daemon.I want to run the django project as daemon. </p> <p>I tried following links to implement this,</p> <ol> <li><p><a href="https://stackoverflow.com/questions/4875326/twisted-creating-a-threadpool-and-then-daemonizing-leads-to-uninformative-hangs">Twisted: Creating a ThreadPool and then daemonizing leads to uninformative hangs</a></p></li> <li><p><a href="http://www.robgolding.com/blog/2011/02/05/django-on-twistd-web-wsgi-issue-workaround/" rel="nofollow noreferrer">http://www.robgolding.com/blog/2011/02/05/django-on-twistd-web-wsgi-issue-workaround/</a></p></li> </ol> <p>But this also not working for me.By this method TCP server is not even listen to the given port. </p> <p>Please help me to figure it out.</p> <h1>UPDATE</h1> <p>I'm sorry for the missing informations.Here is my objectives.</p> <p>I'm beginner in twisted world, so first I'm trying to get my working django project configured under twisted,currently its working well on django testing server or apache via mod_wsgi. </p> <p>To configure it with twisted I used the biding code given below, that code is a combination of two sample's found in the links that I given in the first post.</p> <p>So in-order to integrate django app with twisted I used the following code, file name: "server.py".</p> <pre><code>import sys import os from twisted.application import internet, service from twisted.web import server, resource, wsgi, static from twisted.python import threadpool from twisted.internet import reactor from django.conf import settings import twresource # This file hold implementation of "Class Root". class ThreadPoolService(service.Service): def __init__(self, pool): self.pool = pool def startService(self): service.Service.startService(self) self.pool.start() def stopService(self): service.Service.stopService(self) self.pool.stop() class Root(resource.Resource): def __init__(self, wsgi_resource): resource.Resource.__init__(self) self.wsgi_resource = wsgi_resource def getChild(self, path, request): path0 = request.prepath.pop(0) request.postpath.insert(0, path0) return self.wsgi_resource PORT = 8080 # Environment setup for your Django project files: #insert it to first so our project will get first priority. sys.path.insert(0,"django_project") sys.path.insert(0,".") os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings' from django.core.handlers.wsgi import WSGIHandler def wsgi_resource(): pool = threadpool.ThreadPool() pool.start() # Allow Ctrl-C to get you out cleanly: reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) wsgi_resource = wsgi.WSGIResource(reactor, pool, WSGIHandler()) return wsgi_resource # Twisted Application Framework setup: application = service.Application('twisted-django') # WSGI container for Django, combine it with twisted.web.Resource: # XXX this is the only 'ugly' part: see the 'getChild' method in twresource.Root wsgi_root = wsgi_resource() root = Root(wsgi_root) #multi = service.MultiService() #pool = threadpool.ThreadPool() #tps = ThreadPoolService(pool) #tps.setServiceParent(multi) #resource = wsgi.WSGIResource(reactor, tps.pool, WSGIHandler()) #root = twresource.Root(resource) #Admin Site media files #staticrsrc = static.File(os.path.join(os.path.abspath("."), "/usr/haridas/eclipse_workplace/skgargpms/django/contrib/admin/media/")) #root.putChild("admin/media", staticrsrc) # Serve it up: main_site = server.Site(root) #internet.TCPServer(PORT, main_site).setServiceParent(multi) internet.TCPServer(PORT, main_site).setServiceParent(application) #EOF. </code></pre> <p>Using above code It worked well from command line using "twisted -ny server.py", but when we run it as daemon "twisted -y server.py" it will hang, but the app is listening to the port 8080. I can access it using telnet. </p> <p>I found some fixes for this hanging issue from stackoverflow itself. It helped me to use the code sections given below, which is commented in the above server.py file.</p> <pre><code>multi = service.MultiService() pool = threadpool.ThreadPool() tps = ThreadPoolService(pool) tps.setServiceParent(multi) resource = wsgi.WSGIResource(reactor, tps.pool, WSGIHandler()) root = twresource.Root(resource) </code></pre> <p>and :- </p> <pre><code>internet.TCPServer(PORT, main_site).setServiceParent(multi) </code></pre> <p>instead of using the:-</p> <pre><code>wsgi_root = wsgi_resource() root = Root(wsgi_root) </code></pre> <p>and :- </p> <pre><code>internet.TCPServer(PORT, main_site).setServiceParent(application) </code></pre> <p>The modified method also didn't helped me to avoid the hanging issue.Is any body out there who successfully run the django apps under twisted daemon mode?.</p> <p>I maid any mistakes while combining these codes?, Currently I'm only started to learn the twisted architectures in detail. Please help me to solve this problem</p> <p>Thanks and Regards,</p> <p>Haridas N.</p> <p>Note:- Im looking for the Twisted Application configuration (TAC) file, which integrate django app with twisted and run with out any problem in the daemon mode also.</p> <p>Thank you, Haridas N.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload