本文整理汇总了Python中supervisor.events.notify函数的典型用法代码示例。如果您正苦于以下问题:Python notify函数的具体用法?Python notify怎么用?Python notify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了notify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _log
def _log(self, data):
if data:
config = self.process.config
if config.options.strip_ansi:
data = stripEscapes(data)
if self.childlog:
self.childlog.info(data)
if self.log_to_mainlog:
if not isinstance(data, bytes):
text = data
else:
try:
text = data.decode('utf-8')
except UnicodeDecodeError:
text = 'Undecodable: %r' % data
msg = '%(name)r %(channel)s output:\n%(data)s'
config.options.logger.log(
self.mainlog_level, msg, name=config.name,
channel=self.channel, data=text)
if self.channel == 'stdout':
if self.stdout_events_enabled:
notify(
ProcessLogStdoutEvent(self.process,
self.process.pid, data)
)
else: # channel == stderr
if self.stderr_events_enabled:
notify(
ProcessLogStderrEvent(self.process,
self.process.pid, data)
)
示例2: remove_process_group
def remove_process_group(self, name):
if self.process_groups[name].get_unstopped_processes():
return False
self.process_groups[name].before_remove()
del self.process_groups[name]
events.notify(events.ProcessGroupRemovedEvent(name))
return True
示例3: add_process_group
def add_process_group(self, config):
name = config.name
if name not in self.process_groups:
config.after_setuid()
self.process_groups[name] = config.make_group()
events.notify(events.ProcessGroupAddedEvent(name))
return True
return False
示例4: test_notify_true
def test_notify_true(self):
from supervisor import events
L = []
def callback(event):
L.append(1)
events.callbacks[:] = [(DummyEvent, callback)]
events.notify(DummyEvent())
self.assertEqual(L, [1])
示例5: test_notify_false
def test_notify_false(self):
from supervisor import events
L = []
def callback(event):
L.append(1)
class AnotherEvent:
pass
events.callbacks[:] = [(AnotherEvent, callback)]
events.notify(DummyEvent())
self.assertEqual(L, [])
示例6: test_notify_via_subclass
def test_notify_via_subclass(self):
from supervisor import events
L = []
def callback(event):
L.append(1)
class ASubclassEvent(DummyEvent):
pass
events.callbacks[:] = [(DummyEvent, callback)]
events.notify(ASubclassEvent())
self.assertEqual(L, [1])
示例7: sendRemoteCommEvent
def sendRemoteCommEvent(self, type, data):
""" Send an event that will be received by event listener
subprocesses subscribing to the RemoteCommunicationEvent.
@param string type String for the "type" key in the event header
@param string data Data for the event body
@return boolean Always return True unless error
"""
if isinstance(type, unicode):
type = type.encode("utf-8")
if isinstance(data, unicode):
data = data.encode("utf-8")
notify(RemoteCommunicationEvent(type, data))
return True
示例8: tick
def tick(self, now=None):
""" Send one or more 'tick' events when the timeslice related to
the period for the event type rolls over """
if now is None:
# now won't be None in unit tests
now = time.time()
for event in events.TICK_EVENTS:
period = event.period
last_tick = self.ticks.get(period)
if last_tick is None:
# we just started up
last_tick = self.ticks[period] = timeslice(period, now)
this_tick = timeslice(period, now)
if this_tick != last_tick:
self.ticks[period] = this_tick
events.notify(event(this_tick, self))
示例9: change_state
def change_state(self, new_state, expected=True):
old_state = self.state
if new_state is old_state:
# exists for unit tests
return False
event_class = self.event_map.get(new_state)
if event_class is not None:
event = event_class(self, old_state, expected)
events.notify(event)
if new_state == ProcessStates.BACKOFF:
now = time.time()
self.backoff = self.backoff + 1
self.delay = now + self.backoff
self.state = new_state
示例10: handle_result
def handle_result(self, result):
process = self.process
procname = process.config.name
logger = process.config.options.logger
try:
self.process.group.config.result_handler(process.event, result)
logger.debug('%s: event was processed' % procname)
self._change_listener_state(EventListenerStates.ACKNOWLEDGED)
except RejectEvent:
logger.warn('%s: event was rejected' % procname)
self._change_listener_state(EventListenerStates.ACKNOWLEDGED)
notify(EventRejectedEvent(process, process.event))
except:
logger.warn('%s: event caused an error' % procname)
self._change_listener_state(EventListenerStates.UNKNOWN)
notify(EventRejectedEvent(process, process.event))
示例11: handle_result
def handle_result(self, result):
process = self.process
procname = process.config.name
try:
self.process.group.config.result_handler(process.event, result)
msg = '%s: BUSY -> ACKNOWLEDGED (processed)' % procname
process.listener_state = EventListenerStates.ACKNOWLEDGED
except RejectEvent:
msg = '%s: BUSY -> ACKNOWLEDGED (rejected)' % procname
process.listener_state = EventListenerStates.ACKNOWLEDGED
notify(EventRejectedEvent(process, process.event))
except:
msg = '%s: BUSY -> UNKNOWN' % procname
process.listener_state = EventListenerStates.UNKNOWN
notify(EventRejectedEvent(process, process.event))
process.config.options.logger.debug(msg)
示例12: sendRemoteCommEvent
def sendRemoteCommEvent(self, type, data):
""" Send an event that will be received by event listener
subprocesses subscribing to the RemoteCommunicationEvent.
:param type: String for the "type" key in the event header
:type type: string
:param data: Data for the event body
:type data: string
:return: Always return True unless error
:rtype: boolean
"""
if isinstance(type, unicode):
type = type.encode('utf-8')
if isinstance(data, unicode):
data = data.encode('utf-8')
notify(
RemoteCommunicationEvent(type, data)
)
return True
示例13: toggle_capturemode
def toggle_capturemode(self):
self.capturemode = not self.capturemode
if self.capturelog is not None:
if self.capturemode:
self.childlog = self.capturelog
else:
for handler in self.capturelog.handlers:
handler.flush()
data = self.capturelog.getvalue()
channel = self.channel
procname = self.process.config.name
event = self.event_type(self.process, self.process.pid, data)
notify(event)
msg = "%(procname)r %(channel)s emitted a comm event"
self.process.config.options.logger.debug(msg,
procname=procname,
channel=channel)
for handler in self.capturelog.handlers:
handler.remove()
handler.reopen()
self.childlog = self.mainlog
示例14: _log
def _log(self, data):
if data:
config = self.process.config
if config.options.strip_ansi:
data = stripEscapes(data)
if self.childlog:
self.childlog.info(data)
if self.log_to_mainlog:
msg = '%(name)r %(channel)s output:\n%(data)s'
config.options.logger.log(
self.mainlog_level, msg, name=config.name,
channel=self.channel, data=data)
if self.channel == 'stdout':
if self.stdout_events_enabled:
notify(
ProcessLogStdoutEvent(self.process,
self.process.pid, data)
)
else: # channel == stderr
if self.stderr_events_enabled:
notify(
ProcessLogStderrEvent(self.process,
self.process.pid, data)
)
示例15: runforever
def runforever(self):
events.notify(events.SupervisorRunningEvent())
timeout = 1 # this cannot be fewer than the smallest TickEvent (5)
socket_map = self.options.get_socket_map()
while 1:
combined_map = {}
combined_map.update(socket_map)
combined_map.update(self.get_process_map())
pgroups = list(self.process_groups.values())
pgroups.sort()
if self.options.mood < SupervisorStates.RUNNING:
if not self.stopping:
# first time, set the stopping flag, do a
# notification and set stop_groups
self.stopping = True
self.stop_groups = pgroups[:]
events.notify(events.SupervisorStoppingEvent())
self.ordered_stop_groups_phase_1()
if not self.shutdown_report():
# if there are no unstopped processes (we're done
# killing everything), it's OK to swtop or reload
raise asyncore.ExitNow
for fd, dispatcher in combined_map.items():
if dispatcher.readable():
self.options.poller.register_readable(fd)
if dispatcher.writable():
self.options.poller.register_writable(fd)
r, w = self.options.poller.poll(timeout)
for fd in r:
if fd in combined_map:
try:
dispatcher = combined_map[fd]
self.options.logger.blather(
'read event caused by %(dispatcher)r',
dispatcher=dispatcher)
dispatcher.handle_read_event()
if (not dispatcher.readable()
and not dispatcher.writable()):
self.options.poller.unregister(fd)
except asyncore.ExitNow:
raise
except:
combined_map[fd].handle_error()
for fd in w:
if fd in combined_map:
try:
dispatcher = combined_map[fd]
self.options.logger.blather(
'write event caused by %(dispatcher)r',
dispatcher=dispatcher)
dispatcher.handle_write_event()
if (not dispatcher.readable()
and not dispatcher.writable()):
self.options.poller.unregister(fd)
except asyncore.ExitNow:
raise
except:
combined_map[fd].handle_error()
[ group.transition() for group in pgroups ]
self.reap()
self.handle_signal()
self.tick()
if self.options.mood < SupervisorStates.RUNNING:
self.ordered_stop_groups_phase_2()
if self.options.test:
break