test_wait_task.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 # kate: replace-tabs off; indent-width 4; indent-mode normal
00003 # vim: ts=4:sw=4:noexpandtab
00004 
00005 # Copyright (c) 2012 Stéphane Magnenat, ETHZ Zürich and other contributors
00006 # See file authors.txt for details.
00007 # All rights reserved.
00008 #
00009 # Redistribution and use in source and binary forms, with or without
00010 # modification, are permitted provided that the following conditions are met:
00011 #
00012 #   * Redistributions of source code must retain the above copyright notice,
00013 #     this list of conditions and the following disclaimer.
00014 #   * Redistributions in binary form must reproduce the above copyright notice,
00015 #     this list of conditions and the following disclaimer in the documentation
00016 #     and/or other materials provided with the distribution.
00017 #   * Neither the name of Stéphane Magnenat, ETHZ Zürich, nor the names
00018 #     of the contributors may be used to endorse or promote products derived
00019 #     from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00022 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00025 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00027 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 
00032 import sys
00033 sys.path.append('..')
00034 from teer import *
00035 
00036 def main_task():
00037         def printer(nr):
00038                 counter = 0
00039                 while counter < nr:
00040                         sched.printd(str(counter) + ' (on ' + str(nr) + ')')
00041                         yield WaitDuration(0.5)
00042                         counter += 1
00043                 sched.printd(str(sched.exit_waiting))
00044 
00045         def test_wait_any():
00046                 id1 = sched.new_task(printer(5))
00047                 id2 = sched.new_task(printer(10))
00048                 ret = yield WaitAnyTasks([id1,id2])
00049                 sched.kill_tasks([id1,id2])
00050                 print ret
00051         
00052         def test_wait_all():
00053                 id1 = sched.new_task(printer(5))
00054                 id2 = sched.new_task(printer(10))
00055                 ret = yield WaitAllTasks([id1,id2])
00056                 sched.kill_tasks([id1,id2])
00057                 print ret
00058         
00059         print '\n* Test wait any *\n'
00060         wait_id = sched.new_task(test_wait_any())
00061         yield WaitTask(wait_id)
00062         print '\n * Test wait all *\n'
00063         wait_id = sched.new_task(test_wait_all())
00064         yield WaitTask(wait_id)
00065 
00066 sched = TimerScheduler()
00067 sched.new_task(main_task())
00068 print 'Running scheduler'
00069 sched.run()
00070 print 'All tasks are dead, we better leave this place'
00071 


teer_ros
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:56:00