def start(self): if self.debug: print ('Starting TCP Client - connecting to %s on port %s' % (self.host, self.portnumber)) ##self.client.run() try: background().start() except: pass # assume already running self.client.activate()
def start(self): if self.debug: print 'Starting TCP Client - connecting to %s on port %s' % (self.host, self.portnumber) ##self.client.run() try: background().start() except: pass # assume already running self.client.activate()
def initialize(self): # print "begin initialize..." # if not self._background_initialized: if Foo.dummyComponent is None: Foo.dummyComponent = dummyComponent().activate() if background.background.lock.acquire(False): background.background.lock.release() self.bg = background.background() self.bg.start()
def initialize(self): # print "begin initialize..." if waitForLock(background.background.lock): # print "got it, releasing" background.background.lock.release() # print "new background..." self.bg = background.background(zap=True) # print "starting..." self.bg.start() # print "sleeping..." #time.sleep(1) self.bg.waitUntilSchedulerIsRunning() else: print "COULDN'T ACQUIRE BACKGROUND LOCK" sys.exit(2)
class Reverser(Axon.Component.component): def main(self): while True: if self.dataReady('inbox'): item = self.recv('inbox') self.send(item[::-1], 'outbox') else: self.pause() yield 1 # If using zap=True, number of breaks is increased # background(zap=True).start() background(zap=True).start() # Uncomment this -> ~40% fail, it doesn't seem matter how long we sleep time.sleep(1) # time.sleep(5) reverser = Handle(Reverser()).activate() # There seems that there is not a big difference uncommenting this # time.sleep(1) reverser.put("hello world", "inbox") # There seems that there is not a big difference uncommenting this # time.sleep(1)
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------------- from Axon.background import background from Axon.Handle import Handle from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient background = background().start() import time import Queue p = Handle(SimpleHTTPClient()).activate() p.put("http://google.com","inbox") p.put("http://slashdot.org","inbox") p.put("http://whatismyip.org","inbox") def get_item(handle): while 1: try: item = handle.get("outbox") break except Queue.Empty: time.sleep(0.05)
# See the License for the specific language governing permissions and # limitations under the License. # ------------------------------------------------------------------------- # a slightly more complicated example of a TCP client, where we define an echo. from Kamaelia.Chassis.ConnectedServer import SimpleServer from Kamaelia.Protocol.EchoProtocol import EchoProtocol from Kamaelia.Internet.TCPClient import TCPClient from Axon.background import background from Axon.Handle import Handle import Queue import time background(slowmo=0.01).start() PORT = 1900 # This starts an echo server in the background. SimpleServer(protocol = EchoProtocol, port = PORT).activate() # give the component time to commence listening on a port. time.sleep(0.5) echoClient = Handle(TCPClient(host = "localhost", port = PORT)).activate() while True: echoClient.put(raw_input(">>> "),"inbox") while 1: try: print echoClient.get("outbox") break
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from Axon.background import background from Axon.Handle import Handle from Kamaelia.Codec.Vorbis import VorbisDecode, AOAudioPlaybackAdaptor from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor from Kamaelia.Internet.TCPClient import TCPClient import time import Queue import ao background(slowmo=0.001).start() filename = "./snail.ogg" playStream = Handle(Pipeline(VorbisDecode(), AOAudioPlaybackAdaptor())).activate() # set of components for playing the stream back. host = "bbc.kamaelia.org" port = 1500 client = Handle(TCPClient(host = host, port = port)).activate() # component to grab a stream from the internet filedump = open("streamdump.ogg", "w+b") def get_item(handle):
ping [<__main__.Pinger object at 0xb7c28d0c>] ping [<__main__.Pinger object at 0xb7c28d0c>] This appears to be due to a race hazard, and so 1/2 the time it will succeed, and half the time it fails. This is clearly resolvable. """ import time import Axon from Axon.background import background print background Y = background() print Y Y.start() print "hello" class Pinger(Axon.ThreadedComponent.threadedcomponent): def main(self): while 1: time.sleep(0.5) print "ping" print self.scheduler.listAllThreads() c = 0
ping [<__main__.Pinger object at 0xb7c28d0c>] ping [<__main__.Pinger object at 0xb7c28d0c>] This appears to be due to a race hazard, and so 1/2 the time it will succeed, and half the time it fails. This is clearly resolvable. """ import time import Axon from Axon.background import background print background Y = background() print Y Y.start() print "hello" class Pinger(Axon.ThreadedComponent.threadedcomponent): def main(self): while 1: time.sleep(0.5) print "ping" print self.scheduler.listAllThreads() c = 0 while 1: c +=1
#!/usr/bin/python import time from Axon.background import background from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer from Axon.Handle import Handle background().start() try: import Queue queue = Queue # Python 3 compatibility change except ImportError: # Python 3 compatibility change import queue TD = Handle( TextDisplayer(position=(20, 90), text_height=36, screen_width=900, screen_height=200, background_color=(130,0,70), text_color=(255,255,255) ) ).activate() TB = Handle( Textbox(position=(20, 340), text_height=36, screen_width=900, screen_height=400, background_color=(130,0,70), text_color=(255,255,255)
#!/usr/bin/python import time from Axon.background import background from Kamaelia.UI.Pygame.Text import Textbox, TextDisplayer from Axon.Handle import Handle background().start() try: import Queue queue = Queue # Python 3 compatibility change except ImportError: # Python 3 compatibility change import queue TD = Handle( TextDisplayer(position=(20, 90), text_height=36, screen_width=900, screen_height=200, background_color=(130, 0, 70), text_color=(255, 255, 255))).activate() TB = Handle( Textbox(position=(20, 340), text_height=36, screen_width=900, screen_height=400, background_color=(130, 0, 70), text_color=(255, 255, 255))).activate() message = "hello\n"
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import Axon from Axon.background import background from Axon.Handle import Handle from Kamaelia.UI.Pygame.Ticker import Ticker from Kamaelia.Chassis.Pipeline import Pipeline from Kamaelia.File.ReadFileAdaptor import ReadFileAdaptor import time bg = background(slowmo=0.01).start() ticker1 = Handle(Pipeline( Ticker(background_colour=(128,48,128), render_left = 1, render_top = 1, render_right = 600, render_bottom = 200, position = (100, 250), ) ) ).activate() ticker2 = Handle(Pipeline( Ticker(background_colour=(128,48,128), render_left = 1, render_top = 1,
from Axon.Handle import Handle from Axon.background import background import time, sys class Reverser(Axon.Component.component): def main(self): while True: if self.dataReady('inbox'): item = self.recv('inbox') self.send(item[::-1], 'outbox') else: self.pause() yield 1 # If using zap=True, number of breaks is increased # background(zap=True).start() background(zap=True).start() # Uncomment this -> ~40% fail, it doesn't seem matter how long we sleep time.sleep(1) # time.sleep(5) reverser = Handle(Reverser()).activate() # There seems that there is not a big difference uncommenting this # time.sleep(1) reverser.put("hello world", "inbox") # There seems that there is not a big difference uncommenting this # time.sleep(1)