本文整理汇总了Python中history.History.add方法的典型用法代码示例。如果您正苦于以下问题:Python History.add方法的具体用法?Python History.add怎么用?Python History.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: schedule
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def schedule(self, msgs_to_process=None, timers_to_process=None):
"""Schedule given number of pending messages"""
if msgs_to_process is None:
msgs_to_process = 32768
if timers_to_process is None:
timers_to_process = 32768
while self.queue:
msg = self.queue.popleft()
try:
c = zerorpc.Client(timeout=1)
c.connect('tcp://' + msg.to_node)
except zerorpc.TimeoutExpired:
_logger.info("Drop %s->%s: %s as destination down", msg.from_node, msg.to_node, msg)
History.add("drop", msg)
self.dynamo.retry_request(msg)
if isinstance(msg, ResponseMessage):
# figure out the original request this is a response to
try:
reqmsg = msg.response_to.original_msg
except Exception:
reqmsg = msg.response_to
History.add("deliver", msg)
m = pickle.dumps(msg)
try:
c.rcvmsg(m)
c.close()
except:
print 'time out'
print msg.to_node
self.dynamo.retry_request(msg)
示例2: cancel_timer
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def cancel_timer(cls, tmsg):
"""Cancel the given timer"""
for (this_prio, this_tmsg) in cls.pending:
if this_tmsg == tmsg:
_logger.debug("Cancel timer %s for node %s reason %s", id(tmsg), tmsg.from_node, tmsg.reason)
cls.pending.remove((this_prio, this_tmsg))
History.add("cancel", tmsg)
return
示例3: forward_message
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def forward_message(cls, msg, new_to_node):
"""Forward a message"""
_logger.info("Enqueue(fwd) %s->%s: %s", msg.to_node, new_to_node, msg)
fwd_msg = copy.copy(msg)
fwd_msg.intermediate_node = fwd_msg.to_node
fwd_msg.original_msg = msg
fwd_msg.to_node = new_to_node
cls.queue.append(fwd_msg)
History.add("forward", fwd_msg)
示例4: partition_repair
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def partition_repair(self):
# Repair the partition
History.add("announce", "Repair network partition")
Framework.cuts = []
Framework.schedule(timers_to_process=12)
# Get from node a
a = Node.node['a']
a.get('K1')
Framework.schedule(timers_to_process=0)
示例5: send_message
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def send_message(cls, msg, expect_reply=True):
"""Send a message"""
_logger.info("Enqueue %s->%s: %s", msg.from_node, msg.to_node, msg)
cls.queue.append(msg)
History.add("send", msg)
# Automatically run timers for request messages if the sender can cope
# with retry timer pops
if (expect_reply and
not isinstance(msg, ResponseMessage) and
'rsp_timer_pop' in msg.from_node.__class__.__dict__ and
callable(msg.from_node.__class__.__dict__['rsp_timer_pop'])):
cls.pending_timers[msg] = TimerManager.start_timer(msg.from_node, reason=msg, callback=Framework.rsp_timer_pop)
示例6: pop_timer
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def pop_timer(cls):
"""Pop the first pending timer"""
while True:
(_, tmsg) = cls.pending.pop(0)
if tmsg.from_node.failed:
continue
_logger.debug("Pop timer %s for node %s reason %s", id(tmsg), tmsg.from_node, tmsg.reason)
History.add("pop", tmsg)
if tmsg.callback is None:
# Default to calling Node.timer_pop()
tmsg.from_node.timer_pop(tmsg.reason)
else:
tmsg.callback(tmsg.reason)
return
示例7: course_page
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def course_page(dept, course_id):
try: #format id, else tell user that id is invalid
formatted_id = id_from_url(course_id)
except ValueError:
return '\''+course_id+'\' is not a valid course id.'
try:
res = dbsession.query(Course)
course = res.filter(Course.id == formatted_id).one()
except:
return 'Course \'' + course_id + '\' does not exist.'
#get alt descs for course
res = dbsession.query(AltDesc)
alt_desc_list = list(res.filter(AltDesc.course_id == formatted_id))
#get alt descs for courses that are the same (like CS220 and MATH220)
#and concatenate them together
for same_course in listify(course.same_as):
additional_alt_descs = dbsession.query(AltDesc).filter(AltDesc.course_id == same_course)
alt_desc_list += list(additional_alt_descs)
#remove unapproved alt descs
alt_desc_list = filter(lambda alt_desc: alt_desc.approved, alt_desc_list)
sections = dbsession.query(Section).\
filter( Section.course_id == formatted_id )
term_offerings = OrderedDict()
for term in terms:
term_offerings[term] = sections.filter(Section.term==term)
term_offerings[term] = list(term_offerings[term])
course = search(dbsession, course_id = course.id)
course = course[course.keys()[0]]
form = AltDescForm()
#Appends course title to history
history = History()
history.add(course)
#Sets history cookie
resp = make_response( render_template("course.html",
course=course,
form=form,
alt_descs=alt_desc_list,
terms=term_offerings,
history=history) )
resp.set_cookie('history', str(history), max_age=365*24*60*60) #cookie lasts a year
return resp
示例8: start_timer
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def start_timer(cls, node, reason=None, callback=None, priority=None):
"""Start a timer for the given node, with an option reason code"""
if node.failed:
return None
tmsg = Timer(node, reason, callback=callback)
History.add("start", tmsg)
if priority is None: # default to priority of the node
priority = _priority(tmsg)
_logger.debug("Start timer %s prio %d for node %s reason %s", id(tmsg), priority, node, reason)
# Figure out where in the list to insert
for ii in range(len(cls.pending)):
if priority > cls.pending[ii][0]:
cls.pending.insert(ii, (priority, tmsg))
return tmsg
cls.pending.append((priority, tmsg))
return tmsg
示例9: forward_message
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def forward_message(cls, msg, con, new_to_node):
"""Forward a message"""
_logger.info("Enqueue(fwd) %s->%s: %s", msg.to_node, new_to_node, msg)
fwd_msg = copy.copy(msg)
fwd_msg.intermediate_node = fwd_msg.to_node
fwd_msg.original_msg = msg
fwd_msg.to_node = new_to_node
cls.queue.append(fwd_msg)
History.add("forward", fwd_msg)
#modified
try:
pmsg = pickle.dumps(msg)
return con.rcvmsg(pmsg)
except zerorpc.TimeoutExpired:
print "forward message time out when", msg.from_node, "calls", new_to_node
return False
示例10: send_message
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def send_message(cls, msg, con, expect_reply=True):
"""receive a message"""
_logger.info("Enqueue %s->%s: %s", msg.from_node, msg.to_node, msg)
cls.queue.append(msg)
History.add("receive", msg)
# Automatically run timers for request messages if the sender can cope
# with retry timer pops
if (expect_reply and
not isinstance(msg, ResponseMessage) and
'rsp_timer_pop' in msg.from_node.__class__.__dict__ and
callable(msg.from_node.__class__.__dict__['rsp_timer_pop'])):
cls.pending_timers[msg] = TimerManager.start_timer(msg.from_node, reason=msg, callback=Framework.rsp_timer_pop)
#modified
try:
pmsg = pickle.dumps(msg)
return con.rcvmsg(pmsg)
except zerorpc.TimeoutExpired:
print "time out when", msg.from_node, "calls", msg.to_node
return False
示例11: schedule
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def schedule(cls, msgs_to_process=None, timers_to_process=None):
"""Schedule given number of pending messages"""
if msgs_to_process is None:
msgs_to_process = 32768
if timers_to_process is None:
timers_to_process = 32768
while cls._work_to_do():
_logger.info("Start of schedule: %d (limit %d) pending messages, %d (limit %d) pending timers",
len(cls.queue), msgs_to_process, TimerManager.pending_count(), timers_to_process)
# Process all the queued up messages (which may enqueue more along the way)
while cls.queue:
#modify
msg, con = cls.queue.popleft()
###############################
if msg.to_node.failed:
_logger.info("Drop %s->%s: %s as destination down", msg.from_node, msg.to_node, msg)
History.add("drop", msg)
elif not Framework.reachable(msg.from_node, msg.to_node):
_logger.info("Drop %s->%s: %s as route down", msg.from_node, msg.to_node, msg)
History.add("cut", msg)
else:
_logger.info("Dequeue %s->%s: %s", msg.from_node, msg.to_node, msg)
if isinstance(msg, ResponseMessage):
# figure out the original request this is a response to
try:
reqmsg = msg.response_to.original_msg
except Exception:
reqmsg = msg.response_to
# cancel any timer associated with the original request
cls.remove_req_timer(reqmsg)
History.add("deliver", msg)
msgs_to_process = msgs_to_process - 1
if msgs_to_process == 0:
return
# No pending messages; potentially pop a (single) timer
if TimerManager.pending_count() > 0 and timers_to_process > 0:
# Pop the first pending timer; this may enqueue work
TimerManager.pop_timer()
timers_to_process = timers_to_process - 1
if timers_to_process == 0:
return
示例12: send_message
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def send_message(cls, msg, expect_reply=True):
"""Send a message"""
_logger.info("Enqueue %s->%s: %s", msg.from_node, msg.to_node, msg)
cls.queue.append(msg)
History.add("send", msg)
示例13: cut_wires
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def cut_wires(cls, from_nodes, to_nodes):
History.add("announce", "Cut %s -> %s" % ([str(x) for x in from_nodes], [str(x) for x in to_nodes]))
cls.cuts.append((from_nodes, to_nodes))
示例14: schedule
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
def schedule(cls, msgs_to_process=None, timers_to_process=None):
"""Schedule given number of pending messages"""
if msgs_to_process is None:
msgs_to_process = 32768
if timers_to_process is None:
timers_to_process = 32768
while cls._work_to_do():
_logger.info("Start of schedule: %d (limit %d) pending messages, %d (limit %d) pending timers",
len(cls.queue), msgs_to_process, TimerManager.pending_count(), timers_to_process)
# Process all the queued up messages (which may enqueue more along the way)
while cls.queue:
msg = cls.queue.popleft()
if msg.to_node in cls.block:
_logger.info("Drop %s->%s: %s as destination down", msg.from_node, msg.to_node, msg)
History.add("drop", msg)
else:
try:
c = zerorpc.Client(timeout=1)
c.connect('tcp://' + msg.to_node)
except zerorpc.TimeoutExpired:
_logger.info("Drop %s->%s: %s as destination down", msg.from_node, msg.to_node, msg)
History.add("drop", msg)
continue
if not Framework.reachable(msg.from_node, msg.to_node):
_logger.info("Drop %s->%s: %s as route down", msg.from_node, msg.to_node, msg)
History.add("cut", msg)
_logger.info("Dequeue %s->%s: %s", msg.from_node, msg.to_node, msg)
elif isinstance(msg, ResponseMessage):
# figure out the original request this is a response to
try:
reqmsg = msg.response_to.original_msg
except Exception:
reqmsg = msg.response_to
# cancel any timer associated with the original request
cls.remove_req_timer(reqmsg)
History.add("deliver", msg)
m = pickle.dumps(msg)
try:
c.rcvmsg(m)
c.close()
except:
print 'time out'
cls.queue.append(msg)
print cls.block
for node in cls.nodeList:
if node != msg.to_node:
bmsg = BlockRsp(from_node=msg.from_node, to_node=node, key=msg.to_node, msg_id=None)
cls.queue.append(bmsg)
msgs_to_process = msgs_to_process - 1
if msgs_to_process == 0:
return
# No pending messages; potentially pop a (single) timer
if TimerManager.pending_count() > 0 and timers_to_process > 0:
# Pop the first pending timer; this may enqueue work
TimerManager.pop_timer()
timers_to_process = timers_to_process - 1
if timers_to_process == 0:
return
示例15: Entry
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add [as 别名]
class Entry(gtk.EventBox):
def __init__(self, view):
gtk.EventBox.__init__(self)
self._view = view
hbox = gtk.HBox(False, 3)
hbox.show()
hbox.set_border_width(3)
self._entry = gtk.Entry()
self._entry.modify_font(self._view.style.font_desc)
self._entry.set_has_frame(False)
self._entry.set_name('command-bar')
self._entry.modify_text(gtk.STATE_NORMAL, self._view.style.text[gtk.STATE_NORMAL])
self._entry.set_app_paintable(True)
self._entry.connect('realize', self.on_realize)
self._entry.connect('expose-event', self.on_entry_expose)
self._entry.show()
self._prompt_label = gtk.Label('<b>>>></b>')
self._prompt_label.set_use_markup(True)
self._prompt_label.modify_font(self._view.style.font_desc)
self._prompt_label.show()
self._prompt_label.modify_fg(gtk.STATE_NORMAL, self._view.style.text[gtk.STATE_NORMAL])
self.modify_bg(gtk.STATE_NORMAL, self.background_gdk())
self._entry.modify_base(gtk.STATE_NORMAL, self.background_gdk())
self._entry.connect('focus-out-event', self.on_entry_focus_out)
self._entry.connect('key-press-event', self.on_entry_key_press)
self.connect_after('size-allocate', self.on_size_allocate)
self.connect_after('expose-event', self.on_expose)
self.connect_after('realize', self.on_realize)
self._history = History(os.path.expanduser('~/.gnome2/gedit/commander/history'))
self._prompt = None
hbox.pack_start(self._prompt_label, False, False, 0)
hbox.pack_start(self._entry, True, True, 0)
self.add(hbox)
self.attach()
self._entry.grab_focus()
self._wait_timeout = 0
self._info_window = None
self.connect('destroy', self.on_destroy)
self._history_prefix = None
self._suspended = None
self._handlers = [
[0, gtk.keysyms.Up, self.on_history_move, -1],
[0, gtk.keysyms.Down, self.on_history_move, 1],
[None, gtk.keysyms.Return, self.on_execute, None],
[None, gtk.keysyms.KP_Enter, self.on_execute, None],
[0, gtk.keysyms.Tab, self.on_complete, None],
[0, gtk.keysyms.ISO_Left_Tab, self.on_complete, None]
]
self._re_complete = re.compile('("((?:\\\\"|[^"])*)"?|\'((?:\\\\\'|[^\'])*)\'?|[^\s]+)')
self._command_state = commands.Commands.State()
def view(self):
return self._view
def on_realize(self, widget):
widget.window.set_back_pixmap(None, False)
def on_entry_expose(self, widget, evnt):
ct = evnt.window.cairo_create()
ct.rectangle(evnt.area.x, evnt.area.y, evnt.area.width, evnt.area.height)
bg = self.background_color()
ct.set_source_rgb(bg[0], bg[1], bg[1])
ct.fill()
return False
def on_expose(self, widget, evnt):
ct = evnt.window.cairo_create()
color = self.background_color()
ct.rectangle(evnt.area.x, evnt.area.y, evnt.area.width, evnt.area.height)
ct.clip()
# Draw separator line
ct.move_to(0, 0)
ct.set_line_width(1)
ct.line_to(self.allocation.width, 0)
ct.set_source_rgb(1 - color[0], 1 - color[1], 1 - color[2])
ct.stroke()
return False
def on_size_allocate(self, widget, alloc):
vwwnd = self._view.get_window(gtk.TEXT_WINDOW_BOTTOM).get_parent()
size = vwwnd.get_size()
#.........这里部分代码省略.........