[sldev] Getting started with eventlet and spawning...
Ryan Williams (Which)
rdw at lindenlab.com
Thu Dec 25 10:09:06 PST 2008
Hey Sam, we actually created a separate mailing list for
eventlet-related stuff, because sldev is pretty much for viewer
development only. It's eventletdev at lists.secondlife.com .
Cross-posting there for ya.
I'm not really an expert on spawning, but it looks like you might have
more success not calling wrap_socket_with_coroutine_socket from within
FetchApp. Spawning should handle that for you, modulo the command-line
arguments given it. That's just a shot in the dark though.
And, merry christmas!
Sam's Lists wrote:
> (Yes I am spending Christmas Eve on exactly this... :)
>
> So, I'm trying to set started porting an existing wsgi application
> I've written. The existing app uses Twisted and runs under CherryPy's
> wsgi server. I thought eventlet and spawning would be a nice
> replacement for twisted and cherrypy respectively.
>
> But I'm having trouble. The example from the docs for downloading
> three pages works fine. But when I try and embed the example as a
> wigi app I can't make it work. I've tried a bunch of variations, but
> here's the current one.
>
> #!/usr/bin/env python
>
> urls = ["http://www.google.com",
> "http://wiki.secondlife.com",
> "http://us.i1.yimg.com"]
>
> import time
> from eventlet import coros, httpc, util
> from webob import Request, Response
>
> def fetch(url):
> print "%s fetching %s" % (time.asctime(), url)
> x = httpc.get(url)
> print x
> print "%s fetched %s" % (time.asctime(), url)
>
> def FetchApp(environ, start_response):
> util.wrap_socket_with_coroutine_socket()
> pool = coros.CoroutinePool(max_size=4)
> waiters = []
> for url in urls:
> waiters.append(pool.execute(fetch, url))
> for waiter in waiters:
> waiter.wait()
> resp = Response("done")
> return resp(environ, start_response)
>
>
> Now when I run this as:
> % spawn test_eventlet.FetchApp
>
> and then I make a request with my web browser, I get the folowing output:
>
> (18686) **** Controller starting up at Thu Dec 25 04:52:16 2008
> (18686) spawning 1 children with
> /usr/lib/python2.5/site-packages/Spawning-0.8.7-py2.5.eg
> <http://Spawning-0.8.7-py2.5.eg>
> g/spawning/spawning_child.pyc
> (18686) serving wsgi with configuration:
> (18686) {'app': 'test_eventlet.FetchApp',
> (18686) 'app_factory': 'spawning.wsgi_factory.app_factory',
> (18686) 'args': ['test_eventlet.FetchApp'],
> (18686) 'deadman_timeout': 120,
> (18686) 'dev': True,
> (18686) 'host': '',
> (18686) 'middleware': [],
> (18686) 'num_processes': 1,
> (18686) 'port': 8080,
> (18686) 'processpool_workers': 0,
> (18686) 'source_directories': ['/home/sam/eventlet-fetcher'],
> (18686) 'threadpool_workers': 10,
> (18686) 'watch': None}
> (18687) reloader watching sys.modules
> (18687) using 10 threads
> (18687) wsgi starting up on http://0.0.0.0:8080/
> Thu Dec 25 04:52:20 2008 fetching http://www.google.com
> Thu Dec 25 04:52:20 2008 fetching http://wiki.secondlife.com
> Thu Dec 25 04:52:20 2008 fetching http://us.i1.yimg.com
> Traceback (most recent call last):
> File
> "/usr/lib/python2.5/site-packages/eventlet-0.8-py2.5.egg/eventlet/hubs/hub.py",
> li
> ne 294, in fire_timers
> timer()
> File
> "/usr/lib/python2.5/site-packages/eventlet-0.8-py2.5.egg/eventlet/timer.py",
> line
> 77, in __call__
> cb(*args, **kw)
> File
> "/usr/lib/python2.5/site-packages/eventlet-0.8-py2.5.egg/eventlet/greenlib.py",
> line 314, in switch
> rval = other.switch(value, exc)
> error: cannot switch to a different thread
> Timer raised: Timer(0, <function switch at 0x8cad70>,
> *(<greenlet.greenlet object at 0xbcef90>, [(2, 1, 6, '',
> ('64.233.161.99', 80)), (2, 1, 6, '', ('64.233.161.104', 80)), (2,1,
> 6, '', ('64.233.161.147', 80))]), **{})
> Traceback (most recent call last):
> File
> "/usr/lib/python2.5/site-packages/eventlet-0.8-py2.5.egg/eventlet/hubs/hub.py",
> line 294, in fire_timers
> timer()
> File
> "/usr/lib/python2.5/site-packages/eventlet-0.8-py2.5.egg/eventlet/timer.py",
> line77, in __call__
> cb(*args, **kw)
> File
> "/usr/lib/python2.5/site-packages/eventlet-0.8-py2.5.egg/eventlet/greenlib.py",
> line 314, in switch
> rval = other.switch(value, exc)
> error: cannot switch to a different thread
> Timer raised: Timer(0, <function switch at 0x8cad70>,
> *(<greenlet.greenlet object at 0xc21090>, [(2, 1, 6, '',
> ('204.245.162.32', 80)), (2, 1, 6, '', ('204.245.162.27', 80))]), **{})
>
> What at I doing wrong?
>
> Thanks
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Policies and (un)subscribe information available here:
> http://wiki.secondlife.com/wiki/SLDev
> Please read the policies before posting to keep unmoderated posting privileges
More information about the SLDev
mailing list