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

Python stackless.run函数代码示例

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

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



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

示例1: test_except

    def test_except(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()
        # cheating, can't test for ZeroDivisionError
        except Exception as e:
            rlist.append('E')
        stackless.schedule()
        stackless.schedule()

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


示例2: 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


示例3: mainloop

def mainloop():
    if REACTOR_RUN_NORMAL:
        ftlog.info('Main loop begin. REACTOR_RUN_NORMAL')
        stackless.tasklet(reactor.run)()
        reactor.callLater(0, stackless.schedule)
        stackless.run()
        ftlog.info('Main loop over. REACTOR_RUN_NORMAL')
        return

    loopcount = 0  # 测试代码, 有时接到tcp消息, 却不处理, log也不出, 为何?
    r = reactor  # escape eclipse error
    r.startRunning()
    while r._started:
        try:
            while r._started:
                loopcount += 1
                if loopcount > 1000000000:
                    loopcount = 0
                if loopcount % 100 == 0:
                    ftlog.debug("Main loop 100!")
                # Advance simulation time in delayed event processors.
                r.runUntilCurrent()
                _schedule_reactor()
                t2 = r.timeout()
                t = r.running and t2
                r.doIteration(t)
                _schedule_reactor()
        except:
            ftlog.error("Main loop error!")
        else:
            ftlog.info('Main loop terminated.')
        finally:
            _schedule_reactor()
    ftlog.info('Main loop over.')
    sys.exit(0)
开发者ID:zhaozw,项目名称:hall37,代码行数:35,代码来源:reactor.py


示例4: lifecycle

    def lifecycle(self, t):
        # Initial state - unrun
        self.assertTrue(t.alive)
        self.assertTrue(t.scheduled)
        self.assertEqual(t.recursion_depth, 0)
        # allow hard switching
        t.set_ignore_nesting(1)

        softSwitching = stackless.enable_softswitch(0); stackless.enable_softswitch(softSwitching)
        
        # Run a little
        res = stackless.run(10)
        self.assertEqual(t, res)
        self.assertTrue(t.alive)
        self.assertTrue(t.paused)
        self.assertFalse(t.scheduled)
        self.assertEqual(t.recursion_depth, softSwitching and 1 or 2)

        # Push back onto queue
        t.insert()
        self.assertFalse(t.paused)
        self.assertTrue(t.scheduled)
        
        # Run to completion
        stackless.run()
        self.assertFalse(t.alive)
        self.assertFalse(t.scheduled)
        self.assertEqual(t.recursion_depth, 0)
开发者ID:d11,项目名称:rts,代码行数:28,代码来源:test_miscell.py


示例5: switch

    def switch(self, data=None):
        if not self._tasklet.scheduled:
            self._tasklet.insert()
            stackless.run()

        self._channel.send(data)
        return self._channel.receive()
开发者ID:masamitsu-murase,项目名称:pausable_unittest,代码行数:7,代码来源:continulet.py


示例6: TestMonkeyPatchUDP

    def TestMonkeyPatchUDP(address):
        # replace the system socket with this module
        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"
                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)
                # 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:
            uninstall()
开发者ID:breezechen,项目名称:stacklessexamples,代码行数:33,代码来源:socket_asyncore.py


示例7: lifecycle

    def lifecycle(self, t):
        # Initial state - unrun
        self.assert_(t.alive)
        self.assert_(t.scheduled)
        self.assertEquals(t.recursion_depth, 0)
        # allow hard switching
        t.set_ignore_nesting(1)
        
        # Run a little
        res = stackless.run(10)
        self.assertEquals(t, res)
        self.assert_(t.alive)
        self.assert_(t.paused)
        self.failIf(t.scheduled)
        self.assertEquals(t.recursion_depth, 1)

        # Push back onto queue
        t.insert()
        self.failIf(t.paused)
        self.assert_(t.scheduled)
        
        # Run to completion
        stackless.run()
        self.failIf(t.alive)
        self.failIf(t.scheduled)
        self.assertEquals(t.recursion_depth, 0)
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:26,代码来源:test_miscell.py


示例8: test_bind

    def test_bind(self):
        t = stackless.tasklet()
        wr = weakref.ref(t)

        self.assertFalse(t.alive)
        self.assertIsNone(t.frame)
        self.assertEquals(t.nesting_level, 0)

        t.bind(None)  # must not change the tasklet

        self.assertFalse(t.alive)
        self.assertIsNone(t.frame)
        self.assertEquals(t.nesting_level, 0)

        t.bind(self.task)
        t.setup(False)

        stackless.run()
        self.assertFalse(t.scheduled)
        self.assertTrue(t.alive)
        if stackless.enable_softswitch(None):
            self.assertTrue(t.restorable)
        self.assertIsInstance(t.frame, types.FrameType)

        t.insert()
        stackless.run()

        # remove the tasklet. Must run the finally clause
        t = None
        self.assertIsNone(wr())  # tasklet has been deleted
        self.assertEqual(self.finally_run_count, 1)
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:31,代码来源:test_miscell.py


示例9: 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


示例10: 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


示例11: testSocketIsManaged

    def testSocketIsManaged(self):
        """The goal of this test is to verify that the tasklet created to
        manage the socket, actually starts."""

        # Give the rpc module access to the 'tasklet' class as its stackless
        # module has been replaced with a mock object.
        rpc.stackless.tasklet = stackless.tasklet

        # Make a mock version of '_ManageSocket' we can tell has been called.
        def new_ManageSocket(self):
            new_ManageSocket.called = True
        new_ManageSocket.called = False

        # Inject it in a way where we restore the old version so that
        # subsequent tests are not clobbered by leakage.
        old_ManageSocket = rpc.EndPoint._ManageSocket
        rpc.EndPoint._ManageSocket = new_ManageSocket
        try:
            _socket = DummyClass()
            endpoint = rpc.EndPoint(_socket)
            self.failUnless(stackless.runcount == 2, "_ManageSocket was not launched in a tasklet")
            # Ensure the _ManageSocket tasklet starts.
            stackless.run()
        finally:
            rpc.EndPoint._ManageSocket = old_ManageSocket

        # Verify that the scheduler/tasklet state is correct.
        self.failUnless(stackless.runcount == 1, "The scheduler still contains tasklets")
        # Verify that the tasklet gets started.
        self.failUnless(new_ManageSocket.called, "The mock _ManageSocket function was not called")
开发者ID:breezechen,项目名称:stacklessexamples,代码行数:30,代码来源:test_rpc.py


示例12: 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


示例13: 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


示例14: 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


示例15: _test_watchdog_priority

    def _test_watchdog_priority(self, soft):
        self.awoken = 0
        def runner_func(recursive, start):
            if  recursive:
                stackless.tasklet(runner_func)(recursive-1, start)
            with stackless.atomic():
                stackless.run(2, soft=soft, totaltimeout=True, ignore_nesting=True)
                a = self.awoken
                self.awoken += 1
            if recursive == start:
                # we are the first watchdog
                self.assertEqual(a, 0) #the first to wake up
                self.done += 1 # we were interrupted
            t1.kill()
            t2.kill()

        def task():
            while True:
                for i in xrange(100):
                    i = i
                stackless.schedule()

        t1 = stackless.tasklet(task)()
        t2 = stackless.tasklet(task)()
        t3 = stackless.tasklet(runner_func)(3, 3)
        stackless.run()
        self.assertEqual(self.done, 2)
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:27,代码来源:test_watchdog.py


示例16: 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


示例17: threadfunc

 def threadfunc():
     t = stackless.tasklet(taskletfunc)()
     t.run()
     e1.set()
     while not e2.is_set():
         stackless.run()
         time.sleep(0.001)
     e2.wait() #wait until we can die
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:8,代码来源:test_thread.py


示例18: test_run_paused

 def test_run_paused(self):
     s = stackless.tasklet(lambda: None)
     s.bind(args=())
     self.assertTrue(s.paused)
     with self.switch_trap:
         self.assertRaisesRegex(RuntimeError, "switch_trap", s.run)
     self.assertTrue(s.paused)
     stackless.run()
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:8,代码来源:test_miscell.py


示例19: run_repl

def run_repl():
    import code
    def interact():
        w = open_window()
        code.InteractiveConsole(locals=globals()).interact()
        w.close()
    stackless.tasklet(interact)()
    stackless.run()
开发者ID:euccastro,项目名称:cspdemo,代码行数:8,代码来源:main.py


示例20: testScheduleRemove

 def testScheduleRemove(self):
     #schedule remove doesn't work if it is the only tasklet running under watchdog
     def func(self):
         stackless.schedule_remove()
         self.fail("We shouldn't be here")
     stackless.run() #flush all runnables
     stackless.tasklet(func)(self)
     stackless.run()
开发者ID:newerthcom,项目名称:savagerebirth,代码行数:8,代码来源:test_defects.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python stackless.schedule函数代码示例发布时间:2022-05-27
下一篇:
Python stackless.getruncount函数代码示例发布时间: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