test_wait_duration.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 tick():
00037         rate = sched.create_rate(10)
00038         while True:
00039                 print '.',
00040                 sys.stdout.flush()
00041                 yield Sleep(rate)
00042 
00043 def world():
00044         print 'World'
00045         yield WaitDuration(0.2)
00046         print 'happy'
00047         yield WaitDuration(0.2)
00048         print 'happy'
00049         yield WaitDuration(0.2)
00050         print 'happy'
00051         yield WaitDuration(2)
00052         print 'but...'
00053 
00054 def hello():
00055         tick_tid = sched.new_task(tick())
00056         print 'Hello'
00057         yield WaitDuration(1)
00058         print 'I am rather shy'
00059         yield WaitDuration(2)
00060         print 'I might say it'
00061         world_tid = sched.new_task(world())
00062         print 'I\'m not alone'
00063         yield WaitDuration(0.2)
00064         print 'I talk'
00065         yield WaitDuration(0.2)
00066         print 'I talk'
00067         yield WaitDuration(0.2)
00068         print 'Now I stop talking and wait'
00069         yield WaitTask(world_tid)
00070         print 'World is dead now'
00071         yield WaitDuration(1)
00072         print 'I liked world'
00073         yield WaitDuration(1)
00074         print 'Really, I\'m tired, I will die...'
00075         sched.kill_task(tick_tid)
00076 
00077 sched = TimerScheduler()
00078 sched.new_task(hello())
00079 print 'Running scheduler'
00080 sched.run()
00081 print 'All tasks are dead, we better leave this place'
00082 


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