• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python stackless.tasklet函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stackless.tasklet函数的典型用法代码示例。如果您正苦于以下问题:Python tasklet函数的具体用法?Python tasklet怎么用?Python tasklet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了tasklet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: handle_accept

 def handle_accept(self):
     if self.acceptChannel.balance < 0:
         currentSocket, clientAddress = asyncore.dispatcher.accept(self)
         currentSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
         # Give them the asyncore based socket, not the standard one.
         currentSocket = self.wrap_accept_socket(currentSocket)
         stackless.tasklet(self.acceptChannel.send)((currentSocket, clientAddress))
开发者ID:grant-olson,项目名称:why_stackless,代码行数:7,代码来源:stacklesssocket.py


示例2: test_simple_channel

    def test_simple_channel(self):
        output = []
        def print_(*args):
            output.append(args)
            
        def Sending(channel):
            print_("sending")
            channel.send("foo")

        def Receiving(channel):
            print_("receiving")
            print_(channel.receive())

        ch=stackless.channel()

        task=stackless.tasklet(Sending)(ch)

        # Note: the argument, schedule is taking is the value,
        # schedule returns, not the task that runs next

        #stackless.schedule(task)
        stackless.schedule()
        task2=stackless.tasklet(Receiving)(ch)
        #stackless.schedule(task2)
        stackless.schedule()

        stackless.run()

        assert output == [('sending',), ('receiving',), ('foo',)]
开发者ID:Qointum,项目名称:pypy,代码行数:29,代码来源:test_stackless.py


示例3: testProducerConsumer2

    def testProducerConsumer2(self):
        lock = RLock()
        producerReady = Condition(lock)
        consumerReady = Condition(lock)

        def producer(n, slot):
            for i in xrange(n):
                with producerReady:
                    while slot:
                        producerReady.wait()

                    slot.append(i)
                    consumerReady.notify()

        def consumer(n, slot, result):
            for i in xrange(n):
                with consumerReady:
                    while not slot:
                        consumerReady.wait()

                    result.append(slot[0])
                    del slot[:]
                    producerReady.notify()

        theslot = []
        result = []
        n = 5
        stackless.tasklet(producer)(n, theslot)
        stackless.tasklet(consumer)(n, theslot, result)
        Run()
        self.assertEqual(result, range(n))
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:31,代码来源:locks_unittest.py


示例4: test_scheduling_cleanup

    def test_scheduling_cleanup(self):
        rlist = []
        def f():
            rlist.append('fb')
            stackless.schedule()
            rlist.append('fa')

        def g():
            rlist.append('gb')
            stackless.schedule()
            rlist.append('ga')

        def h():
            rlist.append('hb')
            stackless.schedule()
            rlist.append('ha')

        tf = stackless.tasklet(f)()
        tg = stackless.tasklet(g)()
        th = stackless.tasklet(h)()

        rlist.append('mb')
        stackless.run()
        rlist.append('ma')

        assert rlist == 'mb fb gb hb fa ga ha ma'.split()
开发者ID:Qointum,项目名称:pypy,代码行数:26,代码来源:test_stackless.py


示例5: test_except_full

    def test_except_full(self):
        rlist = []
        def f():
            rlist.append('f')
            return 1/0

        def g():
            rlist.append('bg')
            stackless.schedule()
            rlist.append('ag')

        def h():
            rlist.append('bh')
            stackless.schedule()
            rlist.append('ah')

        tg = stackless.tasklet(g)()
        tf = stackless.tasklet(f)()
        th = stackless.tasklet(h)()

        try:
            stackless.run()
        except ZeroDivisionError:
            rlist.append('E')
        stackless.schedule()
        stackless.schedule()

        assert rlist == "bg f E bh ag ah".split()
开发者ID:Qointum,项目名称:pypy,代码行数:28,代码来源:test_stackless.py


示例6: mainloop

def mainloop():
    tylog.info('Main loop begin.')
    stackless.tasklet(reactor.run)()
    reactor.callLater(0, stackless.schedule)
    stackless.run()
    tylog.info('Main loop over.')
    sys.exit(0)
开发者ID:zhaozw,项目名称:hall37,代码行数:7,代码来源:tytasklet.py


示例7: handle_accept

 def handle_accept(self):
     if self.acceptChannel and self.acceptChannel.balance < 0:
         t = asyncore.dispatcher.accept(self)
         if t is None:
             return
         t[0].setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
         stackless.tasklet(self.acceptChannel.send)(t)
开发者ID:breezechen,项目名称:stacklessexamples,代码行数:7,代码来源:socket_asyncore.py


示例8: runEventLoop

def runEventLoop():
    global loop_running
    if not loop_running:
        event.init()
        event.signal(2, die)
        stackless.tasklet(eventLoop)()
        loop_running = True
开发者ID:afc163,项目名称:lizworkspace,代码行数:7,代码来源:socketlibevent.py


示例9: handle_write

    def handle_write(self):
        if len(self.writeQueue):
            channel, flags, data = self.writeQueue[0]
            del self.writeQueue[0]

            def asyncore_send(self, data, flags = 0):
                try:
                    result = self.socket.send(data, flags)
                    return result
                except stdsocket.error as why:
                    if why.args[0] == EWOULDBLOCK:
                        return 0
                    channel.send_exception(why.__class__, *why.args)
                    if why.args[0] in (ECONNRESET,
                     ENOTCONN,
                     ESHUTDOWN,
                     ECONNABORTED):
                        self.handle_close()
                    return 0

            nbytes = asyncore_send(self, data, flags)
            if channel.balance < 0:
                channel.send(nbytes)
        elif len(self.sendToBuffers):
            data, address, channel, oldSentBytes = self.sendToBuffers[0]
            sentBytes = self.socket.sendto(data, address)
            totalSentBytes = oldSentBytes + sentBytes
            if len(data) > sentBytes:
                self.sendToBuffers[0] = (data[sentBytes:],
                 address,
                 channel,
                 totalSentBytes)
            else:
                del self.sendToBuffers[0]
                stackless.tasklet(channel.send)(totalSentBytes)
开发者ID:Pluckyduck,项目名称:eve,代码行数:35,代码来源:socket.py


示例10: TestMonkeyPatchUDP

    def TestMonkeyPatchUDP(address):
        # replace the system socket with this module
        #oldSocket = sys.modules["socket"]
        #sys.modules["socket"] = __import__(__name__)
        install()
        try:
            def UDPServer(address):
                listenSocket = stdsocket.socket(AF_INET, SOCK_DGRAM)
                listenSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
                listenSocket.bind(address)

                # Apparently each call to recvfrom maps to an incoming
                # packet and if we only ask for part of that packet, the
                # rest is lost.  We really need a proper unittest suite
                # which tests this module against the normal socket
                # module.
                print "waiting to receive"
                data, address = listenSocket.recvfrom(256)
                print "received", data, len(data)
                if len(data) != 256:
                    raise StandardError("Unexpected UDP packet size")

            def UDPClient(address):
                clientSocket = stdsocket.socket(AF_INET, SOCK_DGRAM)
                # clientSocket.connect(address)
                print "sending 512 byte packet"
                sentBytes = clientSocket.sendto("-"+ ("*" * 510) +"-", address)
                print "sent 512 byte packet", sentBytes

            stackless.tasklet(UDPServer)(address)
            stackless.tasklet(UDPClient)(address)
            stackless.run()
        finally:
            #sys.modules["socket"] = oldSocket
            uninstall()
开发者ID:pivot,项目名称:nexus,代码行数:35,代码来源:StacklessSocket.py


示例11: test_with_channel

    def test_with_channel(self):
        rlist = []
        def f(outchan):
            for i in range(10):
                rlist.append('s%s' % i)
                outchan.send(i)
            outchan.send(-1)

        def g(inchan):
            while 1:
                val = inchan.receive()
                if val == -1:
                    break
                rlist.append('r%s' % val)

        ch = stackless.channel()
        t1 = stackless.tasklet(f)(ch)
        t2 = stackless.tasklet(g)(ch)

        stackless.run()

        assert len(rlist) == 20
        for i in range(10):
            (s,r), rlist = rlist[:2], rlist[2:]
            assert s == 's%s' % i
            assert r == 'r%s' % i
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:26,代码来源:test_stackless.py


示例12: __init__

 def __init__(self, count):
     self.count = count
     self.channel = stackless.channel()
     self.valarr = [[ -1 for i in range(self.count) ] for k in range(self.count)]
     self.pings = []
     stackless.tasklet(self.handle)()
     self.initboard()
开发者ID:a8ksh4,项目名称:junk,代码行数:7,代码来源:pingpong2d.py


示例13: handle_read

	def handle_read(self):
		try:
			conn, addr = self.socket.accept()
		except:
			pass
		else:
			tasklet(self.handler)(conn, addr)
开发者ID:ZoomQuiet,项目名称:eurasia,代码行数:7,代码来源:socket2.py


示例14: Run

    def Run(self):
        self.example = Planet(9235632, 6378000.0, 10000.0, 0.15)
        return
        spherical = False
        import renderer
        #spherical = True#False
        def getV(x,y):
            y = (y-90)/180.0 * math.pi
            x = x/180.0 * math.pi
            #print y,x
            vec = math.sin(y)*math.cos(x), math.sin(y)*math.sin(x), math.cos(y)
            sorrows.terrain.SetSeed(self.example.seed)

            height = sorrows.terrain.fBm(8, *vec)
            if height > 0.4:
                color = 1,1,1
            elif height < 0:
                color = 0,0.2*(1.0+height),0.5+abs(height)/2
                height = 0.0
            else:
                color = 0,height,0
            if not spherical:
                return (x,y,height)+color # uncomment for 2d representation
            height =  1 + height*0.2

            return (vec[0] *height, vec[1]*height, vec[2] * height) + color
#            return x,y,self.example.GetSurfaceHeight(vec)-self.example.radius
        stackless.tasklet(renderer.Render, getV)()
开发者ID:rmtew,项目名称:sorrows-mudlib,代码行数:28,代码来源:world.py


示例15: __init__

    def __init__(self,name,circle):
        self.name = name
        self.circle = circle
        circle.append(self)
        self.channel = stackless.channel()

        stackless.tasklet(self.messageLoop)()
开发者ID:Yugnaynehc,项目名称:ProGit,代码行数:7,代码来源:TestGameStackless.py


示例16: TestMonkeyPatchUDP

    def TestMonkeyPatchUDP(address):
        install()
        try:

            def UDPServer(address):
                listenSocket = stdsocket.socket(AF_INET, SOCK_DGRAM)
                listenSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
                listenSocket.bind(address)
                print 'waiting to receive'
                rdata = ''
                while len(rdata) < 512:
                    data, address = listenSocket.recvfrom(4096)
                    print 'received', data, len(data)
                    rdata += data

            def UDPClient(address):
                clientSocket = stdsocket.socket(AF_INET, SOCK_DGRAM)
                print 'sending 512 byte packet'
                sentBytes = clientSocket.sendto('-' + '*' * 510 + '-', address)
                print 'sent 512 byte packet', sentBytes

            stackless.tasklet(UDPServer)(address)
            stackless.tasklet(UDPClient)(address)
            stackless.run()
        finally:
            uninstall()
开发者ID:Pluckyduck,项目名称:eve,代码行数:26,代码来源:socket.py


示例17: startserver

	def startserver( f ):
		while 1:
			newsock = f.accept()
			print "+++ new", newsock
			SL.tasklet(startwork)(newsock)
			import time
			time.sleep(1)
开发者ID:bahamut8348,项目名称:xkcode,代码行数:7,代码来源:test2.py


示例18: pickle_current_frame

def pickle_current_frame():
    result = []  # comment this line to avoid the crash

    def func(current):
        result.append(pickle.dumps(current.frame, -1))
    stackless.tasklet().bind(func, (stackless.current,)).run()
    return result[0]
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:7,代码来源:unpickle_crash_issue61.py


示例19: _reply_to_connections

 def _reply_to_connections(self):
     """
     sends any queues messages
     :return:
     """
     while not self.outbound_message_queue.empty():
         stackless.tasklet(self._send_message)
开发者ID:spiltfish,项目名称:ConnectionLib,代码行数:7,代码来源:ConnectionManager.py


示例20: __init__

    def __init__(self):
        Object.__init__(self)

        self.components = []
        self.componentsByPosition = {}

        stackless.tasklet(self.ManageFire)()
开发者ID:rmtew,项目名称:sorrows-mudlib,代码行数:7,代码来源:world.py



注:本文中的stackless.tasklet函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.print_traceback函数代码示例发布时间:2022-05-27
下一篇:
Python stackless.schedule函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap