Changeset 82
- Timestamp:
- 08/21/07 21:27:13 (1 year ago)
- Files:
-
- projects/AsynCluster/trunk/doc/gevolver/knapsack.py (modified) (10 diffs)
- projects/AsynCluster/trunk/setup.py (modified) (3 diffs)
- projects/Twisted-Goodies/branches/simpleserver-dynamicsite-process-based-wsgi.py (deleted)
- projects/Twisted-Goodies/branches/simpleserver-process-wsgi (copied) (copied from projects/Twisted-Goodies/trunk)
- projects/Twisted-Goodies/branches/simpleserver-process-wsgi/twisted_goodies/misc/__init__.py (copied) (copied from projects/Twisted-Goodies/trunk/twisted_goodies/misc/__init__.py)
- projects/Twisted-Goodies/branches/simpleserver-process-wsgi/twisted_goodies/simpleserver/http/wsgi.py (copied) (copied from projects/Twisted-Goodies/trunk/twisted_goodies/simpleserver/http/wsgi.py) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/AsynCluster/trunk/doc/gevolver/knapsack.py
r14 r82 1 # pbGE: 2 # Grammatical Evolution (GE) run by a "master" server and a bunch of "worker" 3 # clients via Twisted's Perspective Broker (PB). Computations are dispatched 4 # and carried out asynchronously using Twisted's deferred processing 5 # capabilities. 1 # AsynCluster: gevolver 2 # Python-based Grammatical Evolution with attribute grammars 6 3 # 7 # Copyright (C) 2006 by Edwin A. Suominen, http://www.eepatents.com4 # Copyright (C) 2006-2007 by Edwin A. Suominen, http://www.eepatents.com 8 5 # 9 # This code is not currently released for any public use. 6 # This program is free software; you can redistribute it and/or modify it under 7 # the terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 2 of the License, or (at your option) any later 9 # version. 10 # 11 # This program is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 # FOR A PARTICULAR PURPOSE. See the file COPYING for more details. 14 # 15 # You should have received a copy of the GNU General Public License along with 16 # this program; if not, write to the Free Software Foundation, Inc., 51 17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 10 18 11 19 """ … … 17 25 18 26 # Imports 19 from pbge.grammar import TBase, NBase27 from gevolver.grammar import TBase, NBase 20 28 21 29 … … 74 82 class T(TBase): 75 83 """ 76 T = { }84 BNF Grammar Terminal Set 77 85 """ 78 86 def handgun(self, a): … … 81 89 it adds value depending on the danger present. 82 90 """ 83 def _handgun(s):91 def valuer(s): 84 92 s.bulk += 1 85 93 if s.setting.handguns: … … 88 96 s.value -= 10 89 97 90 return Terminal( _handgun, 'handgun')98 return Terminal(valuer, 'handgun') 91 99 92 100 def propane(self, a): … … 101 109 only if the setting isn't dry. 102 110 """ 103 def _pan(s):111 def valuer(s): 104 112 s.bulk += 2 105 113 if not s.setting.dry: 106 114 s.value += 1 107 115 108 return Terminal(_pan, 'pan') 109 110 # TODO from here on 116 return Terminal(valuer, 'pan') 111 117 112 118 def stove(self, a): … … 114 120 A stove is useful if propane and a pan have been brought. 115 121 """ 116 def _stove(s):122 def valuer(s): 117 123 s.bulk += 2 118 124 if 'propane' in a.items and 'pan' in a.items: 119 125 s.value += 2 120 126 121 return Terminal( _stove, 'stove')127 return Terminal(valuer, 'stove') 122 128 123 129 def heater(self, a): … … 125 131 A heater is somewhat useful if it's cold and propane has been brought. 126 132 """ 127 def _heater(s):133 def valuer(s): 128 134 s.bulk += 1 129 135 if s.setting.cold and 'heater' in a.items: 130 136 s.value += 1 131 137 132 return Terminal( _heater, 'heater')138 return Terminal(valuer, 'heater') 133 139 134 140 def literOfWater(self, a): … … 137 143 """ 138 144 s.bulk += 1 139 addedValue = 1 + s.setting.dry + s.setting.dry145 addedValue = 1 + (s.setting.dry and s.setting.hot) 140 146 s.value += addedValue 141 147 … … 143 149 class P(PBase): 144 150 """ 151 BNF Grammar Rule Set 145 152 """ 146 def next(self, a):147 return (148 self.done,149 self.singleItem,150 self.addItem(self.t.literOfWater)151 )152 153 153 def singleItem(self, a): 154 154 possibilites = [self.next] projects/AsynCluster/trunk/setup.py
r16 r82 32 32 33 33 ### Define requirements 34 required = ['sAsync>=0.4', 'Twisted-Goodies>=0.4' ]34 required = ['sAsync>=0.4', 'Twisted-Goodies>=0.4', 'AsynQueue>=0.2'] 35 35 36 36 37 37 ### Define setup options 38 kw = {'version':'0. 1',38 kw = {'version':'0.2', 39 39 'license':'GPL', 40 40 'platforms':'OS Independent', … … 57 57 'Twisted', 'asynchronous', 58 58 'taskqueue', 'queue', 'priority', 'tasks', 'jobs', 59 'cluster', 'clustering', 'parallel', 'grid'] 59 'cluster', 'clustering', 'parallel', 'grid', 60 'genetic', 'evolution', 'evolutionary computing', 'GE', 'GA', 'GP'] 60 61 61 62 kw['classifiers'] = [ … … 78 79 """.split("\n")) 79 80 80 kw['long_description'] = " ""81 kw['long_description'] = " ".join(""" 81 82 Asynchronous operation of a computing cluster with a Node Display Manager (NDM) 82 83 that allows regular workstation usage of cluster nodes with computing jobs 83 running behind the scenes. Includes evolutionary computing tools that make84 effective use of the asynchronous node processing capabilities that are 85 provided.86 """ 84 running behind the scenes. Includes evolutionary computing tools (under 85 construction) that make effective use of the asynchronous node processing 86 capabilities that are provided. 87 """.split("\n")) 87 88 88 89 ### Finally, run the setup projects/Twisted-Goodies/branches/simpleserver-process-wsgi/twisted_goodies/simpleserver/http/wsgi.py
r80 r82 24 24 """ 25 25 26 import os , threading26 import os 27 27 import Queue 28 28 from zope.interface import implements … … 34 34 from twisted.web2.twcgi import createCGIEnvironment 35 35 36 from asynqueue import ThreadQueue 37 38 39 VERBOSE = False 36 from asynqueue.processworker import ChildManager 37 38 40 39 MAX_PENDING = 10 41 40 IP_BAN_SECS = 30.0 … … 48 47 class WSGIMeta(type): 49 48 """ 49 This metaclass instantiates a child process manager and other queue-related 50 attributes that are common to all invoking classes and subclasses. 50 51 """ 51 52 def __new__(mcls, name, bases, dictionary): 52 53 if not hasattr(mcls, 'globalStuff'): 53 54 gs = mcls.globalStuff = {} 54 # Just use one worker in one thread for now 55 gs[' queue'] = ThreadQueue(1)55 # Just use one worker in one thread for now 56 gs['mgr'] = ChildManager() 56 57 gs['pending'] = 0 57 58 gs['handlers'] = [] … … 67 68 A web2 Resource which wraps the given WSGI application callable. 68 69 69 The WSGI application will be called in a separate thread (using70 the reactor threadpool) whenever a request for this resource or71 any lower part of the url hierarchy isreceived.70 The WSGI application will be called in a separate process whenever a 71 request for this resource or any lower part of the url hierarchy is 72 received. 72 73 73 74 This isn't a subclass of resource.Resource, because it shouldn't do any … … 81 82 def __init__(self, application): 82 83 self.application = application 83 self. queue.subscribe(self)84 self.mgr.queue.subscribe(self) 84 85 85 86 def renderHTTP(self, req): 86 87 def done(result, IP): 87 88 if not result or isinstance(result, failure.Failure): 88 if VERBOSE:89 print "Failed request from %s" % IP90 89 self.banIP(IP) 91 90 if handler in self.handlers: … … 144 143 old = cls.pending 145 144 cls.pending = new 146 if VERBOSE and new != old:147 print "Pending: %02d -> %02d" % (old, new)148 145 if new > MAX_PENDING and cls.handlers: 149 146 if new > min([old, 2*MAX_PENDING]): 150 147 oldestHandler = cls.handlers.pop(0) 151 if VERBOSE:152 print "Stopping handler:", oldestHandler153 148 oldestHandler.stopProducing() 154 149 … … 269 264 Call this if this input stream is backing things up too much. 270 265 """ 271 if VERBOSE:272 print "Closing laggard input stream..."273 266 self.stream.finish() 274 267 … … 306 299 class WSGIHandler(object): 307 300 """ 301 Each HTTP request is handled by an instance of me, constructed in the child 302 process. 308 303 """ 309 304 implements(interfaces.IPushProducer)
