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

Python stackless.getruncount函数代码示例

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

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



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

示例1: testChannel

    def testChannel(self):

        c = stackless.channel()

        recvd = []

        def ch1():
            for i in range(10):
                recvd.append(c.receive())

        def ch2():
            for i in range(10):
                c.send(i)

        child1 = stackless.tasklet(ch1)()
        child2 = stackless.tasklet(ch2)()

        self.assertEquals(3, stackless.getruncount()) #main

        while stackless.getruncount() > 1:
            stackless.schedule()

        self.assertEquals(range(10), recvd)

        self.assertEquals(1, stackless.getruncount()) #main
开发者ID:JoyTeam,项目名称:concurrence,代码行数:25,代码来源:teststackless.py


示例2: testSchedule

    def testSchedule(self):

        res1 = []
        res2 = []

        def ch1():
            for i in range(10):
                res1.append((i, stackless.getruncount()))
                stackless.schedule()

        def ch2():
            for i in range(10):
                res2.append((i, stackless.getruncount()))
                stackless.schedule()

        child1 = stackless.tasklet(ch1)()
        child2 = stackless.tasklet(ch2)()

        self.assertEquals(3, stackless.getruncount()) #main + ch1, ch2

        while stackless.getruncount() > 1:
            stackless.schedule()

        self.assertEquals([(0, 3), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3), (6, 3), (7, 3), (8, 3), (9, 3)], res1)
        self.assertEquals([(0, 3), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3), (6, 3), (7, 3), (8, 3), (9, 3)], res2)

        self.assertEquals(1, stackless.getruncount()) #main
开发者ID:JoyTeam,项目名称:concurrence,代码行数:27,代码来源:teststackless.py


示例3: doit

 def doit():
     result = []
     child1 = stackless.tasklet(ch1)(result)
     child2 = stackless.tasklet(ch2)(result)
     self.assertEquals(3, stackless.getruncount())
     while stackless.getruncount() > 1:
         stackless.schedule()
     return result
开发者ID:JoyTeam,项目名称:concurrence,代码行数:8,代码来源:teststackless.py


示例4: recv_tasklet

def recv_tasklet():
    while True:
        print "recv enter %d" % stackless.getruncount()
#        print "recv data: " + channel.receive()
        try:
            print "recv data: " + channel.receive()
        except Exception,e:
            print "recv get cexeption:" + e.message
        print "recv leave %d" % stackless.getruncount()
开发者ID:likebeta,项目名称:test,代码行数:9,代码来源:stackless_channel.py


示例5: test_getruncount

    def test_getruncount(self):
        assert stackless.getruncount() == 1
        def with_schedule():
            assert stackless.getruncount() == 2

        t1 = stackless.tasklet(with_schedule)()
        assert stackless.getruncount() == 2
        stackless.schedule()
        def with_run():
            assert stackless.getruncount() == 1

        t2 = stackless.tasklet(with_run)()
        stackless.run()
开发者ID:Qointum,项目名称:pypy,代码行数:13,代码来源:test_stackless.py


示例6: child

 def child(r):
     r.b1 = c.balance
     r.rc1 = stackless.getruncount()
     r.cur1 = stackless.getcurrent()
     r.blocked1 = r.cur1.blocked
     r.alive1 = r.cur1.alive
     try:
         c.receive()
     finally:
         r.b2 = c.balance
         r.rc2 = stackless.getruncount()
         r.cur2 = stackless.getcurrent()
         r.blocked2 = r.cur2.blocked
         r.alive2 = r.cur2.alive
开发者ID:JoyTeam,项目名称:concurrence,代码行数:14,代码来源:teststackless.py


示例7: test_insert_balance

 def test_insert_balance(self):
     """ Test that insert into the runqueue of a remote thread does not affect the
     bookkeeping of the current thread.
     """
     thread, task = self.create_thread_task()
     try:
         task.remove()
         before = stackless.getruncount()
         task.insert()
         after = stackless.getruncount()
         # only the runnable count on the remote thread
         # should change
         self.assertEqual(before, after)
     finally:
         thread.join()
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:15,代码来源:test_thread.py


示例8: testSendInsert

  def testSendInsert(self):
    channel_obj = stackless.channel()
    self.assertEqual(None, channel_obj.queue)
    tasklet1 = stackless.tasklet(lambda: 1 / 0)()
    tasklet2 = stackless.tasklet(channel_obj.receive)()
    tasklet2.run()
    self.assertRaisesStr(
        RuntimeError, 'You cannot remove a blocked tasklet.',
        tasklet2.remove)
    # channel_obj.send inserts tasklet2 after current, and since tasklet1 was
    # after current, the insertion runs tasklet1 eventually, which triggers
    # the ZeroDivisionError, propagated to current (== main).
    self.assertRaises(ZeroDivisionError, channel_obj.send, 0)
    self.assertEqual(1, stackless.getruncount())
    self.assertEqual(None, channel_obj.queue)

    channel_obj.preference = 1  # Prefer the sender.
    tasklet1 = stackless.tasklet(lambda: 1 / 0)()
    tasklet2 = stackless.tasklet(channel_obj.receive)()
    self.assertEqual(False, tasklet2.blocked)
    self.assertEqual(True, tasklet2.scheduled)
    tasklet2.run()
    self.assertEqual(True, tasklet2.blocked)
    self.assertEqual(True, tasklet2.scheduled)
    self.assertEqual(tasklet1, stackless.getcurrent().next)
    self.assertEqual(None, channel_obj.send(0))
    self.assertEqual(tasklet1, stackless.getcurrent().next)
    self.assertEqual(tasklet2, stackless.current.prev)
    tasklet1.remove()
    stackless.schedule()
开发者ID:breezechen,项目名称:syncless,代码行数:30,代码来源:stackless_test.py


示例9: testInterthreadCommunication

    def testInterthreadCommunication(self):
        ''' Test that tasklets in different threads sending over channels to each other work. '''    
        self.assertEqual(stackless.getruncount(), 1, "Leakage from other tests, with tasklets still in the scheduler.")

        commandChannel = stackless.channel()

        def master_func():
            commandChannel.send("ECHO 1")
            commandChannel.send("ECHO 2")
            commandChannel.send("ECHO 3")
            commandChannel.send("QUIT")

        def slave_func():
            while 1:
                command = commandChannel.receive()
                if command == "QUIT":
                    break

        def scheduler_run(tasklet_func):
            t = stackless.tasklet(tasklet_func)()
            while t.alive:
                stackless.run()

        thread = threading.Thread(target=scheduler_run, args=(master_func,))
        thread.start()

        scheduler_run(slave_func)
开发者ID:d11,项目名称:rts,代码行数:27,代码来源:test_channel.py


示例10: ManageSleepingTasklets

def ManageSleepingTasklets(threadID):
    global sleepingTasklets, lock, running, threadIDByChannelID, sleepCountByThread

    sleepingTasklets = []
    while running:
        if len(sleepingTasklets):
            lock.acquire(True)
            endTime = sleepingTasklets[0][0]
            if endTime <= time.time():
                channel = sleepingTasklets[0][1]
                del sleepingTasklets[0]
                threadID = threadIDByChannelID[id(channel)]
                sleepCountByThread[threadID] -= 1
                lock.release()

                # We have to send something, but it doesn't matter what as it is not used.
                channel.send(None)
            else:
                lock.release()
        elif stackless.getruncount() == 1:
            # Give up if there are no more sleeping tasklets.  Otherwise the two
            # threads keep on running endlessly.
            print "Sleeping tasklet exited due to no remaining work."
            break
        stackless.schedule()
    else:
        print threadID, "Sleeping tasklet exited due to change in 'running' flag"
开发者ID:breezechen,项目名称:stacklessexamples,代码行数:27,代码来源:interThreadChannels.py


示例11: run

    def run(channel, func, *args, **kwargs):
        r"""
        Runs function `func` with the given arguments on jobman
        channel `chan`.
        """
        try:
            with open('state.ckpt', 'rb') as f:
                t = load(f)
            assert t.restorable
            t.insert()
        except IOError:
            t = stackless.tasklet(func)(*args, **kwargs)

        while stackless.getruncount() > 1:
            stackless.schedule()
            mess = channel.switch()
            if mess is not None:
                with open('state.tmp', 'wb') as f:
                    save(t, f)
                os.rename('state.tmp', 'state.ckpt')
                channel.save()
                if mess == 'stop' or mess == 'finish-up':
                    t.kill()
                    return channel.INCOMPLETE
        channel.save()
        return channel.COMPLETE
开发者ID:Sandy4321,项目名称:pynnet,代码行数:26,代码来源:checkpointing.py


示例12: tearDown

 def tearDown(self):
   self.assertEqual(stackless.main, stackless.getcurrent())
   main_tasklet = stackless.main
   try:
     self.assertEqual(1, stackless.getruncount())
   finally:
     while main_tasklet is not main_tasklet.prev:
       main_tasklet.prev.kill()
开发者ID:breezechen,项目名称:syncless,代码行数:8,代码来源:stackless_test.py


示例13: a_main_tasklet

def a_main_tasklet():
    threadID = 2

    stackless.tasklet(ManageSleepingTasklets)(threadID)

    stackless.tasklet(looping_tasklet)(threadID, 1)

    print threadID, "runcount.1", stackless.getruncount()
    stackless.run()
开发者ID:dnslj,项目名称:python-labs,代码行数:9,代码来源:threadscheduling.py


示例14: testChannelMultiReceiver

    def testChannelMultiReceiver(self):

        c = stackless.channel()
        xs = []
        def ch(i):
            xs.append((i, c.receive()))

        child1 = stackless.tasklet(ch)(1)
        child2 = stackless.tasklet(ch)(2)

        self.assertEquals(3, stackless.getruncount()) #main

        while stackless.getruncount() > 1:
            stackless.schedule()

        self.assertEquals(1, stackless.getruncount()) #main

        self.assertEquals([], xs)
开发者ID:JoyTeam,项目名称:concurrence,代码行数:18,代码来源:teststackless.py


示例15: setUp

    def setUp(self):
        self._ran_AsTaskletTestCase_setUp = True
        if stackless.enable_softswitch(None):
            self.assertEqual(stackless.current.nesting_level, 0)

        super(StacklessTestCase, self).setUp()  # yes, its intended: call setUp on the grand parent class
        self.assertEqual(stackless.getruncount(), 1, "Leakage from other tests, with %d tasklets still in the scheduler" % (stackless.getruncount() - 1))
        if withThreads:
            self.assertEqual(threading.activeCount(), 1, "Leakage from other threads, with %d threads running (1 expected)" % (threading.activeCount()))
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:9,代码来源:support.py


示例16: child1

        def child1():
            i = 0
            while True:
                i += 1
                #print 'c', i
                r.rc1 = stackless.getruncount()
                r.cur1 = stackless.getcurrent()
                r.blocked1 = r.cur1.blocked
                r.alive1 = r.cur1.alive

                try:
                    stackless.schedule()
                except TaskletExit:
                    #print 'kill'
                    r.rc2 = stackless.getruncount()
                    r.cur2 = stackless.getcurrent()
                    r.blocked2 = r.cur2.blocked
                    r.alive2 = r.cur2.alive
                    raise
开发者ID:JoyTeam,项目名称:concurrence,代码行数:19,代码来源:teststackless.py


示例17: testTempval

  def testTempval(self):
    def Worker(items):
        items.append(stackless.schedule())
        items.append(stackless.schedule(None))
        items.append(stackless.schedule('foo'))
        items.append(stackless.schedule(42))
  
    items = []
    tasklet_obj = stackless.tasklet(Worker)(items)
    self.assertEqual(None, tasklet_obj.tempval)
    self.assertEqual([], items)
    stackless.current.tempval = 5
    self.assertEqual(stackless.getcurrent(), stackless.schedule())
    self.assertEqual(None, stackless.current.tempval)
    self.assertEqual(tasklet_obj, tasklet_obj.tempval)
    self.assertEqual([], items)
    stackless.schedule()
    self.assertEqual(None, tasklet_obj.tempval)
    self.assertEqual([tasklet_obj], items)
    stackless.schedule()
    self.assertEqual('foo', tasklet_obj.tempval)
    self.assertEqual([tasklet_obj, None], items)
    tasklet_obj.tempval = False
    stackless.schedule()
    self.assertEqual([tasklet_obj, None, False], items)
    self.assertEqual(42, tasklet_obj.tempval)
    stackless.schedule()
    self.assertEqual([tasklet_obj, None, False, 42], items)
    # Upon TaskletExit.
    self.assertEqual(None, tasklet_obj.tempval)
    self.assertEqual(1, stackless.getruncount())
    self.assertEqual(stackless.getcurrent(), stackless.schedule())
    self.assertEqual(None, stackless.current.tempval)
    self.assertEqual(43, stackless.schedule(43))
    # This seems to be a strange Stackless quirk, this should be 43.
    self.assertEqual(None, stackless.getcurrent().tempval)
    self.assertEqual(54, stackless.schedule_remove(54))
    self.assertEqual(None, stackless.current.tempval)

    def Worker2(items, main_tasklet):
      items.append(stackless.getcurrent().tempval)
      items.append(stackless.schedule(44))
      items.append(stackless.current.tempval)
      main_tasklet.insert()

    del items[:]
    stackless.tasklet(Worker2)(items, stackless.getcurrent())
    self.assertEqual(55, stackless.schedule_remove(55))
    self.assertEqual(None, stackless.current.tempval)
    self.assertEqual([None, 44, None], items)

    self.assertRaisesStr(AssertionError, '', stackless.schedule,
                         stackless.bomb(AssertionError))
    self.assertRaisesStr(AssertionError, 'foo', stackless.schedule,
                         stackless.bomb(AssertionError, 'foo'))
开发者ID:breezechen,项目名称:syncless,代码行数:55,代码来源:stackless_test.py


示例18: Start

def Start():
    try:
        a = A()
        stackless.tasklet(a.bug)()
        stackless.schedule()
        raise Exception

    finally:
        this = stackless.getcurrent()
        while stackless.getruncount() > 1:
            this.next.kill()
开发者ID:d11,项目名称:rts,代码行数:11,代码来源:bajo_crash.py


示例19: run

def run():
    """Run a bunch of tasks, until they all complete"""
    # have to add error handling like above
    while stackless.getruncount() > 1:
        try:
            # running until the end or until something happens
            victim = stackless.run_watchdog(MAX_TIMESLICE)
            if victim:
                print "THIS THREAD WAS PROBABLY STUCK IN AN INFINITE LOOP AND HAS BEEN NUKED!!!",
            # todo: kill the task cleanly
        except Exception, e:
            print "Exception occoured:", e
开发者ID:develersrl,项目名称:dspython,代码行数:12,代码来源:uthread_ccp.py


示例20: eventLoop

def eventLoop():
    global loop_running
    global event_errors
    
    while sockets.values():
        # If there are other tasklets scheduled, then use the nonblocking loop,
        # else, use the blocking loop
        if stackless.getruncount() > 2: # main tasklet + this one
            event.loop(True)
        else:
            event.loop(False)
        stackless.schedule()
    loop_running = False
开发者ID:afc163,项目名称:lizworkspace,代码行数:13,代码来源:socketlibevent.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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