当前位置: 首页>>代码示例>>Python>>正文


Python stackless.getruncount函数代码示例

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


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


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