本文整理汇总了Python中timer.Timer.restart方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.restart方法的具体用法?Python Timer.restart怎么用?Python Timer.restart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.restart方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getPostById
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import restart [as 别名]
def getPostById():
totalRuns = config.executions
connection = pymysql.connect(**config.dbConfig)
cursor = connection.cursor()
timer = Timer()
meanTime = 0
percentConfig = totalRuns / 100
print("==================================== Post By Id Query ====================================")
print("SELECT obj FROM wp_posts WHERE id = post_id;")
for run in range(totalRuns):
postId = randint(1, config.totalPosts)
query = "SELECT {} FROM wp_posts WHERE id = {}".format('text', postId)
timer.restart()
cursor.execute(query)
meanTime += timer.get_seconds()
percent = (run / totalRuns) * 100
if (run % percentConfig) == 0:
print("Completed: {:.0f} % ".format(percent), end = '\r')
print("Completed 100 %")
print("Mean query execution time : {:.10f} seconds".format(meanTime / totalRuns))
connection.close()
print("")
print("Example Query")
print(query)
print("")
return meanTime / totalRuns
示例2: collectionQuery3
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import restart [as 别名]
def collectionQuery3():
totalRuns = config.executions
connection = pymysql.connect(**config.dbConfig)
cursor = connection.cursor()
percentConfig = totalRuns / 100
timer = Timer()
meanTime = 0
limit = 20
print("=================================== Collection Query 3 ===================================")
print(" SELECT text_id AS id, p_text AS text, p_published AS published FROM tag_query3 LEFT JOIN text ON text_id = text.id WHERE p_country = 1 p_type = 'postType' AND p_rank < `postRank` AND p_site = 'site' ORDER BY p_rank DESC LIMIT 20;")
for run in range(totalRuns):
postType = config.postTypes[randint(0, 9)]
postRank = randint(1, config.totalPosts - 1)
country = config.countries[randint(0, 3)]
site = config.siteConfig[randint(0, 19)]
query = "SELECT text_id AS id, p_text AS text, p_published AS published FROM tag_query3 LEFT JOIN text ON text_id = text.id WHERE p_{} = 1 AND p_type = '{}' AND p_rank < {} AND p_site = '{}' ORDER BY p_rank DESC LIMIT {}".format(country, postType, postRank, site, limit)
timer.restart()
cursor.execute(query)
meanTime += timer.get_seconds()
percent = (run / totalRuns) * 100
if (run % percentConfig) == 0:
print("Completed: {:.0f} % ".format(percent), end = '\r')
print("Completed 100 %")
print("Mean query execution time : {:.10f} seconds".format(meanTime / totalRuns))
connection.close()
print("")
print("Example Query")
print(query)
print("")
return meanTime / totalRuns
示例3: collectionQuery2
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import restart [as 别名]
def collectionQuery2():
fake = Faker()
totalRuns = config.executions
connection = pymysql.connect(**config.dbConfig)
cursor = connection.cursor()
limit = 20
timer = Timer()
meanTime = 0
percentConfig = totalRuns / 100
tags = []
config.getTags(tags)
print("=================================== Collection Query 2 ===================================")
print("SELECT text_id AS id, p_text AS text FROM wp_tags AS t LEFT JOIN post2tag ON t.id = tag_id LEFT JOIN tag_query2 ON post_id = text_id LEFT JOIN text ON text_id = text.id WHERE t.name = 'tagName' AND p_site = 'site' AND p_country = 1 AND p_rank < rank ORDER BY p_rank DESC LIMIT 20")
for run in range(totalRuns):
tagName = tags[randint(0, config.totalTags - 1)]
postRank = randint(1, config.totalPosts)
site = config.siteConfig[randint(0, 19)]
country = config.countries[randint(0, 3)]
query = "SELECT text_id AS id, p_text AS text FROM wp_tags AS t LEFT JOIN post2tag ON t.id = tag_id LEFT JOIN tag_query2 ON post_id = text_id LEFT JOIN text ON text_id = text.id WHERE t.name = '{}' AND p_site = '{}' AND p_{} = 1 AND p_rank < {} ORDER BY p_rank DESC LIMIT {}".format(tagName, site, country, postRank, limit)
timer.restart()
cursor.execute(query)
meanTime += timer.get_seconds()
percent = (run / totalRuns) * 100
if (run % percentConfig) == 0:
print("Completed: {:.0f} % ".format(percent), end = '\r')
print("Completed 100 %")
print("Mean query execution time : {:.10f} seconds".format(meanTime / totalRuns))
connection.close()
print("")
print("Example Query")
print(query)
print("")
return meanTime / totalRuns
示例4: Player
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import restart [as 别名]
class Player(TextEntity):
def __init__(self):
TextEntity.__init__(self, self, 0)
self.rateOfFire = 250
self.shooting = False
self.shootingTime = Timer().start()
self.fire_x = 0
self.fire_y = 0
self.fire_vel = 50
self.name = 'Player'
self.moveRate = 50
self.moving = False
self.moveTime = Timer().start()
self.move_vel = 7
self.vel_y_max = 10
self.vel_x_max = 10
self.resistance_x = 35.0
self.resistance_y = 35.0
self.levelMax = 20
self.levelCur = 0
self.levelFuzzieEx = 5 #Chance of a fuzzie spawning during the time (20% chance)
#self.constaccel_y = 20.0
#self.vel_x_max = 100.0
#self.vel_y_max = 100.0
# self.accel_y = 0.0
#self.resistance_x = 1.0
def left(self, key, state):
if state == True:
self.moving |= MOVE_LEFT
else:
self.moving &= ~MOVE_LEFT
def right(self, key, state):
if state == True:
self.moving |= MOVE_RIGHT
else:
self.moving &= ~MOVE_RIGHT
def up(self, key, state):
if state == True:
self.moving |= MOVE_UP
else:
self.moving &= ~MOVE_UP
def down(self, key, state):
# POWER SLIDE!!!
#if state == True:
# self.resistance_x -= 600
#else: self.resistance_x += 600
if state == True:
self.moving |= MOVE_DOWN
else:
self.moving &= ~MOVE_DOWN
def _move(self):
if self.moveTime.elapsed() < self.moveRate:
return
x = y = 0
if self.moving & MOVE_LEFT: x -= self.move_vel
if self.moving & MOVE_RIGHT: x += self.move_vel
if self.moving & MOVE_UP: y -= self.move_vel
if self.moving & MOVE_DOWN: y += self.move_vel
self.impulse(x, y)
self.moveTime.restart()
def _fire(self, x, y):
if self.shootingTime.elapsed() < self.rateOfFire:
return
if not x and not y: return
getScene().add(Bullet(self, 3, x, y), 3)
self.shootingTime.restart()
def fireUp(self, key, state):
if self.shooting and not state:
self.shooting -= 1
self.fire_y += self.fire_vel
elif state == True:
self.shooting += 1
self.fire_y += -self.fire_vel
def fireDown(self, key, state):
if self.shooting and not state:
self.shooting -= 1
self.fire_y -= self.fire_vel
elif state == True:
self.shooting += 1
self.fire_y += self.fire_vel
def fireLeft(self, key, state):
if self.shooting and not state:
self.shooting -= 1
self.fire_x += self.fire_vel
elif state == True:
self.shooting += 1
self.fire_x += -self.fire_vel
def fireRight(self, key, state):
if self.shooting and not state:
self.shooting -= 1
#.........这里部分代码省略.........
示例5: Runner
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import restart [as 别名]
class Runner(object):
"""The Runner class handles most of the core mechanics
of Gizmo including the timer loop as well as
interfacing with with both the modes and the GUI."""
def __init__(self, mode=None):
self.logger = logging.getLogger('Runner')
self.logger.setLevel(logging.DEBUG)
self.logger.debug('Starting Gizmo...')
#init gui
self.gui = gui.GUI()
self.gui.create()
#init runner
self.initQueryVars()
self.refreshDelay = .075
self.initTimer()
self.logger.debug('Initiated')
#set mode
self.mode = None
self.setMode(mode)
self.logger.debug('Gizmo ready')
def close(self, *args):
"""Resets the timer and deletes the gui"""
self.running = False
self.timer.reset()
self.gui.close()
self.logger.debug('Gizmo ended')
def setMode(self, mode):
"""Set the runner's mode.
If the mode is not valid, don't change the current mode,
and if the current mode is None, default to modes.DEFAULT.
Then update the gui's mode if it exists.
"""
if mode not in modes.ALL.keys():
self.logger.error('Mode %s does not exist: %s' % (mode, modes.ALL.keys()))
else:
self.mode = modes.ALL[mode](self)
if self.mode == None:
self.mode = modes.ALL[modes.DEFAULT](self)
self.logger.debug('%s Mode' % self.mode)
if hasattr(self, "gui"):
self.gui.setMode(self.mode)
def initQueryVars(self):
"""Create variables associated with querying actions.
self.query -> the input string entered by the user
self.lastQuery -> the last query that was run
self.isQueried -> whether or not the query has been run
self.isListed -> whether or not the results of the query have been listed
self.optionChanged -> whether or not any options of the current mode have been changed
"""
self.query = ''
self.lastQuery = ''
self.isQueried = False
self.isListed = False
self.optionChanged = False
#makeshift ordered dict
self.results = []
self.doAppend = False
def initTimer(self):
"""Instance the Timer class and start the timer"""
self.timer = Timer(self.refreshDelay, self.refreshDeferred, -1)
if not self.timer.started:
self.timer.start()
else:
self.timer.restart()
self.running = True
self.logger.debug('Timer initiated')
def refreshDeferred(self, *args, **kwargs):
"""Call self.refresh, but deferred, so that the timer may run correctly"""
evalDeferred(Callback(self.refresh, *args, **kwargs))
def refresh(self, *args, **kwargs):
"""Execute the main loop.
This is where the runner executes the active mode's query methods
and then updates the gui based on the results."""
#kill the runner if the window has been closed
if not self.running:
return
if not self.gui.windowExists():
self.close()
return
#update from gui
self.query = self.gui.getQuery()
#check for mode changes and special input
if self.checkSearchSignals():
return
#if self.optionChanged:
#check for change
if self.query != self.lastQuery:
#.........这里部分代码省略.........
示例6: FootBox
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import restart [as 别名]
#.........这里部分代码省略.........
self.init_ui()
self.timer = Timer(3000, self.__clear_tips)
Dispatcher.connect("button-change", self.set_button)
Dispatcher.connect("set-tip", self.set_tip)
event_manager.add_callback("update-delete-button", self.__on_update_delete_button)
def __on_update_delete_button(self, name, obj, data):
#self.btn_delete.set_child_visible(data)
self.queue_draw()
def expose_line(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
style.draw_out_line(cr, rect)
def init_ui(self):
self.tip_align = gtk.Alignment(0, 0.5, 0, 1)
self.tip = Label("",
text_x_align=pango.ALIGN_CENTER,
label_width=500)
self.tip_align.set_padding(5, 5, 20, 0)
self.tip_align.add(self.tip)
self.btn_delete = Button(_("Delete"))
self.btn_delete.connect("clicked", self.delete_click)
self.btn_delete.set_no_show_all(True)
self.btn_save = Button()
self.btn_save.connect("clicked", self.button_click)
button_box = gtk.HBox(spacing=10)
button_box.pack_start(self.btn_delete)
button_box.pack_start(self.btn_save)
self.buttons_align = gtk.Alignment(1, 0.5, 0, 0)
self.buttons_align.set_padding(0, 0, 0, 10)
self.buttons_align.add(button_box)
self.pack(self, [self.tip_align], True, True)
self.pack_end(self.buttons_align, False, False)
def pack(self, parent, widgets, expand=False, fill=False):
for widget in widgets:
parent.pack_start(widget, expand, fill)
def set_lock(self, state):
self.__setting_module.set_lock(state)
def get_lock(self):
return self.__setting_module.get_lock()
def set_button(self, widget, content, state):
self.btn_save.set_label(_("Save"))
self.btn_save.set_sensitive(state)
def delete_click(self, widget):
if self.focus_connection:
Dispatcher.delete_setting(self.focus_connection)
Dispatcher.to_main_page()
def show_delete(self, connection):
self.btn_delete.show()
self.focus_connection = connection
def hide_delete(self):
self.btn_delete.hide()
self.focus_connection = None
#if content == "save":
#if state and not self.get_lock():
#Dispatcher.emit("setting-saved")
#else:
#self.btn_save.set_label(_("connect"))
#self.btn_save.set_sensitive(False)
#else:
#self.btn_save.set_label(_("connect"))
#self.btn_save.set_sensitive(True)
def get_button(self):
return self.__setting_module.get_button_state()
def set_setting(self, module):
self.__setting_module = module
def button_click(self, widget):
#if self.btn_save.label == "save":
Dispatcher.emit("setting-saved")
#elif self.btn_save.label == _("connect"):
#Dispatcher.set_tip("setting saved")
#Dispatcher.emit("setting-appled")
def __clear_tips(self):
self.tip.set_text("")
def set_tip(self, widget, new_tip):
self.tip.set_text(_("Tip:") + new_tip)
self.timer.restart()
示例7: Section
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import restart [as 别名]
class Section(gtk.VBox):
# Section prototype
def __init__(self):
gtk.VBox.__init__(self)
self.timer = Timer(200, self.action_after_toggle)
def load(self, toggle, content=[]):
self.toggle = toggle
self.content_box = gtk.VBox(spacing=0)
self.pack_start(self.toggle, False, False)
self.toggle.switch.connect("toggled", self.toggle_callback)
self.tree = TreeView([])
self.tree.set_expand_column(1)
self.tree.draw_mask = self.draw_mask
content.insert(0, self.tree)
for c in content:
self.content_box.pack_start(c, False, False)
self.align = self._set_align()
self.pack_start(self.align, False, False)
self.show_all()
def init_state(self):
pass
def set_active(self, state):
self.toggle.set_active(state)
def draw_mask(self, cr, x, y, w, h):
cr.set_source_rgb(1, 1, 1)
cr.rectangle(x, y, w, h)
cr.fill()
def _set_align(self):
align = gtk.Alignment(0,0,1,0)
align.set_padding(0, 0, PADDING, 11 + 11)
return align
def toggle_callback(self, widget):
if self.timer.alive():
self.timer.restart()
else:
self.timer.start()
def action_after_toggle(self):
is_active = self.toggle.get_active()
if is_active:
if self.content_box not in self.align.get_children():
self.align.add(self.content_box)
self.show_all()
self.td = ToggleThread(self.get_list, self.tree, self.toggle_on_after)
self.td.start()
else:
self.align.remove(self.content_box)
self.td.stop_run()
self.toggle_off()
def toggle_on(self):
'''
method cb when toggle on
'''
pass
def toggle_on_after(self):
pass
def toggle_off(self):
pass
def get_list(self):
pass
def section_show(self):
self.set_no_show_all(False)
self.show_all()
def section_hide(self):
self.set_no_show_all(True)
self.hide()
def space_box(self):
space = gtk.VBox()
space.set_size_request(-1, 15)
return space