本文整理汇总了Python中Timer.start方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.start方法的具体用法?Python Timer.start怎么用?Python Timer.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer.start方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LegMotion
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
class LegMotion(object):
def __init__(self, startValues, endValues, time = 5.0):
self.startValues = startValues
self.endValues = endValues
self.time = time
self.motionTimer = Timer()
self.start()
def start(self):
self.motionTimer.start()
def currentValues(self, dt):
return LegMotion.extrapolateBatch(self.startValues, self.endValues, self.motionTimer.elapsedTime() + dt, self.time)
def isDone(self):
return self.motionTimer.elapsedTime() > self.time
@staticmethod
def extrapolate(startValue, endValue, currentTime, totalTime):
if currentTime > totalTime:
return endValue
return startValue + (endValue - startValue) * (currentTime / totalTime)
@staticmethod
def extrapolateBatch(startValues, endValues, currentTime, totalTime):
if len(startValues) != len(endValues):
print("Error: startValues and endValues must have the same length in LegMotion.extrapolateBatch()")
res = []
for i in range(len(startValues)):
res.append(LegMotion.extrapolate(startValues[i], endValues[i], currentTime, totalTime))
return res
示例2: test_2
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
def test_2(db,collectionName,save):
time_total=Timer()
time_total.start()
#****************
documents=getAllDocuments(db,collectionName,save)
time_total.stop()
print("Total:{}, load time:{}".format(len(documents),time_total.elapsed))
示例3: test_3
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
def test_3(db,collectionName,search_doc,projection={},save=0,limit=0):
time_total=Timer()
time_total.start()
#****************
c= db[collectionName]
#search_doc={}
#search_doc["f1xxxxxxxx"]= search_str
#cursor=c.find(search_doc,projection)
if projection:
cursor=c.find(search_doc,projection).limit(limit)
else:
cursor=c.find(search_doc).limit(limit)
#cursor=c.find()
documentList=[]
if save:
documentList=list(cursor)
#documents=getAllDocuments(db,collectionName,1)
time_total.stop()
print("Total:{}, search time:{}".format(cursor.count(with_limit_and_skip=True),
time_total.elapsed))
# if limit:
# print("Total:{}, search time:{}".format(limit,time_total.elapsed))
# else:
# print("Total:{}, search time:{}".format(cursor.count(),time_total.elapsed))
return documentList
示例4: Transition
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
class Transition(PubSub):
def __init__(self, current, next):
PubSub.__init__(self)
self.current = current
self.next = next
self.timer = Timer()
self.timer.on('tick', self.on_timer)
self.timer.on('finished', self.on_timer_finished)
self.timer.on('started', self.on_timer_started)
self.parent_temp = None
def start(self, delay=0, duration='infinite', interval=0, repeats='infinite', message_type='tick'):
if self.current.parent == None or self.current == self.next:
return
if self.current.transitioning or self.next.transitioning:
print 'stopping'
return
self.emitter = self.current._stage
self.timer.start(self.emitter, delay, duration, interval, repeats, message_type)
def on_timer_started(self):
self.current.transitioning = True
self.next.transitioning = True
self.next.transition_target = [self.current.x, self.current.y, self.next.width, self.next.height]
self.on_start()
self.emit('started')
self.parent_temp = self.next.parent
self.current.parent.add_child(self.next)
if self.current.parent.on_stage:
self.next.enter(self.current)
def on_start(self):
pass
def on_timer(self):
pass
def on_stop(self):
pass
def on_timer_finished(self, event, **kwargs):
self.emit('finished', event = event, args = kwargs)
self.current.parent.remove_child(self.current)
self.current.transitioning = False
self.next.transitioning = False
self.next.transition_target = None
if self.parent_temp is not None:
self.parent_temp.add_child(self.current)
self.current.exit(self.next)
self.on_stop()
示例5: TestTimer
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
class TestTimer(unittest.TestCase):
def setUp(self):
self.tm = Timer(OpenRTM_aist.TimeValue())
def tearDown(self):
self.tm.__del__()
OpenRTM_aist.Manager.instance().shutdownManager()
time.sleep(0.1)
def test_start_stop(self):
self.tm.start()
self.tm.stop()
def test_invoke(self):
self.tm.registerListenerFunc(test().func, OpenRTM_aist.TimeValue())
self.tm.registerListenerFunc(test().func, OpenRTM_aist.TimeValue())
self.tm.invoke()
def test_registerListener(self):
self.tm.registerListener(test(), OpenRTM_aist.TimeValue())
self.tm.invoke()
pass
def test_registerListenerObj(self):
self.tm.registerListenerObj(test(), test.func, OpenRTM_aist.TimeValue())
self.tm.invoke()
def test_registerListenerFunc(self):
self.tm.registerListenerFunc(test().func, OpenRTM_aist.TimeValue())
self.tm.invoke()
def test_unregisterListener(self):
obj = OpenRTM_aist.ListenerObject(test(),test.func)
self.tm.registerListener(obj, OpenRTM_aist.TimeValue())
self.assertEqual(self.tm.unregisterListener(obj),True)
self.assertEqual(self.tm.unregisterListener(obj),False)
示例6: test_1
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
def test_1(idList,save,projection={}):
time_total=Timer()
time_total.start()
t = Timer()
t.start()
#****************
documentList=[]
for id in range(len(idList)):
if type(idList[id])==str:
_id=ObjectId(idList[id])
else:
_id=idList[id]
if projection:
doc=model.find_one({"_id": _id},projection)
else:
doc=model.find_one({"_id": _id})
# doc=model.find_one({"_id": idList[id]})
if save:
documentList.append(doc)
if id % 10000 == 0 or idList==0:
t.stop()
print(str(id)+" : "+str(t.elapsed))
t.reset()
t.start()
time_total.stop()
print("Total:{}, load time:{}".format(len(idList),time_total.elapsed))
return documentList
示例7: len
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
record[recordFieldName]=recordFieldValue
records.append(record)
if len(records):
field_values_array.append(dict(Record=records))
field[fieldName]=field_values_array
data_section_2.append(field)
modelElement["data_section_2"]=data_section_2
return modelElement
def uniq(seq):
seen = set()
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]
if __name__ == '__main__':
t = Timer()
t.start()
#input_file='C:\\IdeaProjects\\hh_api_test\\MongoTest\\exp_types_formatted_few_elements.xml'
#***input_file='exp_types_formatted_few_elements.xml'
input_file='C:\\Users\mdu\\Documents\\qpr_export\\exp.xml'
#input_file='C:\\Users\mdu\\Documents\\qpr_export\\exp_types_formatted_few_elements_dots.xml'
#***input_file='C:\\Users\МишинДЮ\\Documents\\qpr_export\\exp.xml'
events = ("start", "end")
context = etree.iterparse(input_file,events = events, tag=('{www.qpr.com}ModelElement'))
count=0
dot_key_count=0
key_count=0
elements_with_dot_count=0
# key_path="./descendant-or-self::Attribute/Record/Field/@Name[contains(., '.')]|" \
# "./descendant-or-self::*/@AttributeName[# contains(., '.')]"
key_path_1="./www.qpr.com:Attribute/www.qpr.com:Record/www.qpr.com:Field[@Name[contains(., '.')]]"
示例8: MainGame
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
class MainGame(object):
# Creates and initializes all member
# variables
def initVars(self):
self.width = 0
self.height = 0
# Objects for Cars, Logs, Frogs, and Turtles
self.cars = []
self.logs = []
self.frogs = []
self.winning_frogs = []
self.dead_frogs = []
self.turtles = []
self.fly = GameObject(os.path.join('images', "fly_big.png"))
self.fly.image.set_colorkey((0, 0, 0))
self.fly_appear_time = 12
self.fly_appear_timer = Timer(self.fly_appear_time)
self.fly_timer = Timer(self.fly_appear_time / 2)
self.croc = Croc(os.path.join('images', "croc_sprites_big.png"))
# Background
self.background = pygame.image.load(os.path.join('images', "background.png"))
self.background_music = pygame.mixer.Sound(os.path.join('sounds','bgmusic.ogg'))
self.frog_win_sound = pygame.mixer.Sound(os.path.join('sounds', 'frogwin.ogg'))
self.frog_win_sound.set_volume(1000)
# Vars for UI element data
self.score = 0
self.timeSinceNew = 0
self.level = 1
self.message = ""
# Surfaces for UI elements
self.scoreSurface = None
self.levelSurface = None
self.timeRemainingSurface = None
self.liveSurface = pygame.image.load(os.path.join("images", "safe_frog_big.png")).subsurface(Rect(0, 0, 40, 35))
self.messageSurface = None
# Rects
self.timeRemainingRect = Rect(0, 10, BARWIDTH, 22)
self.goalRects = []
# More pygame stuff. Timer and font
self.clock = pygame.time.Clock()
self.font = pygame.font.Font(os.path.join('fonts', "FreeMonoBold.ttf"), 22)
self.carSpeed = 1
self.num_logs = 3
self.lives = 5
self.frog_died = False
self.frog_won = False
self.game_over = False
self.level_complete = False
self.fly_shown = False
self.level_complete_time = 0
self.paused = False
self.croc_in_level = False
self.back_to_menu = False
self.timer = Timer(FROG_LIFE)
self.game_over_time = 0
self.powerup_time = 3
self.powerup_timer = Timer(self.powerup_time)
# Returns whether or not the game is
# ready to return to the menu
def is_over(self):
return self.back_to_menu
# Returns whether or not the game is paused
def is_paused(self):
return self.paused
# Starts the timer and plays the background
# music
def startGame(self):
self.background_music.play(-1)
self.timer.start()
# stops the background music
def endGame(self):
self.background_music.stop()
def __init__(self, w, h):
self.initVars()
self.width = w
self.height = h
self.timeRemainingRect.left = self.width / 2 - self.timeRemainingRect.width / 2 - 20
self.initializeElements()
#.........这里部分代码省略.........
示例9: remove_dots
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
remove_dots(item)
if '.' in key:
data[key.replace('.', '\uff0E')] = data[key]
#data[key.replace('.', '#')] = data[key]
del data[key]
if type(data)is list:
for item in data:
#remove_dots(item)
if type(item)is dict or type(item)is list:
remove_dots(item)
#if item is dict: data[key] = remove_dots(data[key])
return data
if __name__ == '__main__':
time_total=Timer()
time_total.start()
t = Timer()
t.start()
# start_time=datetime.now()
# print("Start processing: "+start_time.strftime("%d.%m.%Y %H:%M:%S.%f"))
client = MongoClient()
client.drop_database("modelDB")
db=client.modelDB
model = db.model
#input_file='C:\\IdeaProjects\\hh_api_test\\MongoTest\\exp_types_formatted_few_elements.xml'
#***input_file='exp_types_formatted_few_elements.xml'
input_file='C:\\Users\mdu\\Documents\\qpr_export\\exp.xml'
#***input_file='C:\\Users\МишинДЮ\\Documents\\qpr_export\\exp.xml'
events = ("start", "end")
示例10: run_hefesto_morb
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import start [as 别名]
def run_hefesto_morb():
for thing in os.listdir(home_dir_list[0] + "/MORB_Control_Files"):
print "\n" + "Opening HeFESTo for " + str(thing) + "\n"
time.sleep(2)
if "control" in os.listdir(home_dir_list[0]):
os.remove(home_dir_list[0] + "/control")
else:
pass
os.chdir(home_dir_list[0] + "/MORB_Control_Files")
print "Copying" + str(thing) + " to path " + home_dir_list[0] + "..." + "\n"
todir = home_dir_list[0] + "/" + "control"
copyfromdir = home_dir_list[0] + "/MORB_Control_Files/" + str(thing)
shutil.copy(copyfromdir, todir)
os.chdir(home_dir_list[0])
#src = str(thing)
#drc = "control"
#os.rename(src, drc)
print("Performing calculations on {thing!r} ...".format(**vars()))
print "\n"
print "\n" + "Opening HeFESTo for calculations on " + str(thing) + " ..." + "\n"
print "\n"
#working_dir = os.curdir()
#Popen(["main"], cwd=working_dir, stdin=PIPE)
argz = home_dir_list[0] + "/main"
p = subprocess.Popen(argz, stdin=None, stdout=None)
t = Timer(800, p.kill)
print "\n" + "Timeout timer started. 800 seconds until the process is terminated and the loop continues..." + "\n"
t.start()
t.communicate()
t.cancel()
print "\n" + "Copying output files to" + home_dir_list[0]+ "/MORB_Output_Files' directory..." + "\n"
try:
os.remove("control")
except:
print "\n" + "Control file not found!" + "\n"
pass
if "fort.66" in os.listdir(home_dir_list[0]):
print "\n" + "fort.66 found!" + "\n"
theoutputfile66 = home_dir_list[0] + "/" + "fort.66"
outputtodir66 = home_dir_list[0] + "/MORB_Output_Files/fort.66_files/" + "fort.66."+str(thing)+"_morb"
shutil.move(theoutputfile66, outputtodir66)
else:
print "fort.66." + str(thing) + " not found!"
pass
if "fort.58" in os.listdir(home_dir_list[0]):
print "\n" + "fort.58 found!" + "\n"
theoutputfile58 = home_dir_list[0] + "/" + "fort.58"
outputtodir58 = home_dir_list[0] + "/MORB_Output_Files/fort.58_files/" + "fort.58."+str(thing)+"_morb"
shutil.move(theoutputfile58, outputtodir58)
else:
print "fort.58." + str(thing) + " not found!"
pass
if "fort.59" in os.listdir(home_dir_list[0]):
print "\n" + "fort.59 found!" + "\n"
theoutputfile59 = home_dir_list[0] + "/" + "fort.59"
outputtodir59 = home_dir_list[0] + "/MORB_Output_Files/fort.59_files/" + "fort.59."+str(thing)+"_morb"
shutil.move(theoutputfile59, outputtodir59)
else:
print "fort.59." + str(thing) + " not found!"
pass
print "LOOP FINISHED FOR " + str(thing)
time.sleep(2)
#except Exception:
# traceback.print_exc()
# print "\n"
# print "Calculation failure for " + str(thing) + ". Moving on..."
# print "\n"
else:
print "\n"
print "Done with MORB HeFESTo calculations. Exiting script..." + "\n\n\n\n"
print "___________________________________________________________"
print "\n"