本文整理汇总了Python中blinker.signal方法的典型用法代码示例。如果您正苦于以下问题:Python blinker.signal方法的具体用法?Python blinker.signal怎么用?Python blinker.signal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blinker
的用法示例。
在下文中一共展示了blinker.signal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_safe
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def send_safe(signal, logger, sender, **kwargs):
"""
Send a signal and catch any exception which may be raised during it's
emission. Details regarding the error that occurs (including a stack trace)
are logged to the specified *logger*. This is suitable for allowing signals
to be emitted in critical code paths without interrupting the emitter.
:param str signal: The name of the signal to send safely.
:param logger: The logger to use for logging exceptions.
:type logger: :py:class:`logging.Logger`
:param sender: The sender for this signal emission.
:param kwargs: The key word arguments to be forward to the signal as it is sent.
"""
return tuple(send_safe_iter(signal, logger, sender, **kwargs))
# campaign signals
示例2: _send_safe_campaign_alerts
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def _send_safe_campaign_alerts(campaign, signal_name, sender, **kwargs):
alert_subscriptions = tuple(subscription for subscription in campaign.alert_subscriptions if not subscription.has_expired)
logger = logging.getLogger('KingPhisher.Server.CampaignAlerts')
logger.debug("dispatching campaign alerts for '{0}' (sender: {1!r}) to {2:,} active subscriptions".format(signal_name, sender, len(alert_subscriptions)))
if not alert_subscriptions:
return
signal = blinker.signal(signal_name)
if not signal.receivers:
logger.warning("users are subscribed to '{0}', and no signal handlers are connected".format(signal_name))
return
if not signal.has_receivers_for(sender):
logger.info("users are subscribed to '{0}', and no signal handlers are connected for sender: {1}".format(signal_name, sender))
return
for subscription in alert_subscriptions:
results = signals.send_safe(signal_name, logger, sender, alert_subscription=subscription, **kwargs)
if any((result for (_, result) in results)):
continue
logger.warning("user {0} is subscribed to '{1}', and no signal handlers succeeded to send an alert".format(subscription.user.name, signal_name))
示例3: _do_rpc_method
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def _do_rpc_method(self, *args, **kwargs):
self.connection.settimeout(smoke_zephyr.utilities.parse_timespan('20s')) # set a timeout as a fail safe
self.rpc_session_id = self.headers.get(server_rpc.RPC_AUTH_HEADER, None)
self.semaphore_acquire()
http_method_handler = None
try:
signals.request_handle.send(self)
http_method_handler = getattr(super(KingPhisherRequestHandler, self), 'do_RPC')
http_method_handler(*args, **kwargs)
except errors.KingPhisherAbortRequestError as error:
if http_method_handler is None:
self.logger.debug('rpc request aborted by a signal handler')
else:
self.logger.info('rpc request aborted')
if not error.response_sent:
self.respond_not_found()
finally:
self.semaphore_release()
self.connection.settimeout(None)
示例4: unset
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def unset(self, *fields):
"""Unset the given list of fields for this document."""
# Send update signal
signal('update').send(self.__class__, frames=[self])
# Clear the fields from the document and build the unset object
unset = {}
for field in fields:
self._document.pop(field, None)
unset[field] = True
# Update the document
self.get_collection().update_one(
{'_id': self._id},
{'$unset': unset}
)
# Send updated signal
signal('updated').send(self.__class__, frames=[self])
示例5: insert_many
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def insert_many(cls, documents):
"""Insert a list of documents"""
from mongoframes.queries import to_refs
# Ensure all documents have been converted to frames
frames = cls._ensure_frames(documents)
# Send insert signal
signal('insert').send(cls, frames=frames)
# Prepare the documents to be inserted
documents = [to_refs(f._document) for f in frames]
# Bulk insert
ids = cls.get_collection().insert_many(documents).inserted_ids
# Apply the Ids to the frames
for i, id in enumerate(ids):
frames[i]._id = id
# Send inserted signal
signal('inserted').send(cls, frames=frames)
return frames
示例6: delete_many
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def delete_many(cls, documents):
"""Delete multiple documents"""
# Ensure all documents have been converted to frames
frames = cls._ensure_frames(documents)
all_count = len(documents)
assert len([f for f in frames if '_id' in f._document]) == all_count, \
"Can't delete documents without `_id`s"
# Send delete signal
signal('delete').send(cls, frames=frames)
# Prepare the documents to be deleted
ids = [f._id for f in frames]
# Delete the documents
cls.get_collection().delete_many({'_id': {'$in': ids}})
# Send deleted signal
signal('deleted').send(cls, frames=frames)
示例7: blinker_publish
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def blinker_publish(topic, message):
_log.info("Sending blinker signal to: pagure - topic: %s", topic)
ready = blinker.signal("pagure")
ready.send("pagure", topic=topic, message=message)
示例8: send_safe_iter
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def send_safe_iter(signal, logger, sender, **kwargs):
utilities.assert_arg_type(signal, str, 1)
utilities.assert_arg_type(logger, (logging.Logger, logging.LoggerAdapter), 2)
signal = blinker.signal(signal)
for receiver in signal.receivers_for(sender):
try:
result = receiver(sender, **kwargs)
except Exception:
calling_frame = inspect.stack()[1]
logger.error("an error occurred while emitting signal '{0}' from {1}:{2}".format(signal, calling_frame[1], calling_frame[2]), exc_info=True)
else:
yield (receiver, result)
return
示例9: _do_http_method
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def _do_http_method(self, *args, **kwargs):
# This method wraps all of the default do_* HTTP verb handlers to
# provide error handling and (for non-RPC requests) path adjustments.
# This also is also a high level location where the throttle semaphore
# is managed which is acquired for all RPC requests. Non-RPC requests
# can acquire it as necessary and *should* release it when they are
# finished with it, however if they fail to do so or encounter an error
# the semaphore will be released here as a fail safe.
self.connection.settimeout(smoke_zephyr.utilities.parse_timespan('20s')) # set a timeout as a fail safe
self.rpc_session_id = self.headers.get(server_rpc.RPC_AUTH_HEADER, None)
# delete cached properties so they are handled per request instead of connection.
for cache_prop in ('_campaign_id', '_message_id', '_visit_id'):
if hasattr(self, cache_prop):
delattr(self, cache_prop)
self.adjust_path()
self._session = db_manager.Session()
http_method_handler = None
try:
signals.request_handle.send(self)
http_method_handler = getattr(super(KingPhisherRequestHandler, self), 'do_' + self.command)
http_method_handler(*args, **kwargs)
except errors.KingPhisherAbortRequestError as error:
if http_method_handler is None:
self.logger.debug('http request aborted by a signal handler')
else:
self.logger.info('http request aborted')
if not error.response_sent:
self.respond_not_found()
finally:
if self.semaphore_acquired:
self.logger.warning('http request failed to cleanly release resources')
self.semaphore_release()
self._session.close()
self.connection.settimeout(None)
示例10: __init__
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def __init__(self, connection_pool):
self.SR = redis.StrictRedis(connection_pool=connection_pool)
self._g = None
self._signal = signal('mm-status')
示例11: __init__
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def __init__(self, name="baked",**kvargs):
super(self.__class__, self).__init__(name)
self.inExec = self.createInputPin(DEFAULT_IN_EXEC_NAME, 'ExecPin', None, self.compute)
self.createInputPin("Stop", 'ExecPin', None, self.stop)
self.outExec = self.createOutputPin(DEFAULT_OUT_EXEC_NAME, 'ExecPin')
self.signal=self.createInputPin('signalName', 'StringPin', 'blink')
self.data=self.createInputPin('signalMessage', 'StringPin')
self.d3=self.createInputPin('signalObject', 'FCobjPin')
a=self.createInputPin('sleep', 'FloatPin',10)
a.annotationDescriptionDict={ "ValueRange":(0.,300.)}
a=self.createInputPin('loops', 'IntPin',1)
a.annotationDescriptionDict={ "ValueRange":(0.,100.)}
示例12: subscribe
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def subscribe(self, *args, **kwargs):
sayl()
from blinker import signal
sn=self.getData('signalName')
send_data = signal(sn)
@send_data.connect
def receive_data(sender, **kw):
print("%r: caught signal from %r, data %r" % (self.name,sender, kw))
print ("SENDER",sender)
try:
self.sender = sender
self.kw = kw
except:
print("PROBLEME mit sendern")
return
self.setData("senderName",sender)
self.setData("senderMessage",self.kw['message'])
self.setData("senderObject",self.kw['obj'])
self.setColor(b=0,a=0.4)
self.outExec.call()
return ("got return from "+ self.name)
self.r=receive_data
示例13: unsubscribe
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def unsubscribe(self, *args, **kwargs):
from blinker import signal
sn=self.getData('signalName')
send_data = signal(sn)
send_data.disconnect(self.r)
sayl()
self.r=None
self.sender = None
self.kw = None
示例14: owned_pre_save
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def owned_pre_save(sender, document, **kwargs):
'''
Owned mongoengine.pre_save signal handler
Need to fetch original owner before the new one erase it.
'''
if not isinstance(document, Owned):
return
changed_fields = getattr(document, '_changed_fields', [])
if 'organization' in changed_fields:
if document.owner:
# Change from owner to organization
document._previous_owner = document.owner
document.owner = None
else:
# Change from org to another
# Need to fetch previous value in base
original = sender.objects.only('organization').get(pk=document.pk)
document._previous_owner = original.organization
elif 'owner' in changed_fields:
if document.organization:
# Change from organization to owner
document._previous_owner = document.organization
document.organization = None
else:
# Change from owner to another
# Need to fetch previous value in base
original = sender.objects.only('owner').get(pk=document.pk)
document._previous_owner = original.owner
示例15: owned_post_save
# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def owned_post_save(sender, document, **kwargs):
'''
Owned mongoengine.post_save signal handler
Dispatch the `Owned.on_owner_change` signal
once the document has been saved including the previous owner.
The signal handler should have the following signature:
``def handler(document, previous)``
'''
if isinstance(document, Owned) and hasattr(document, '_previous_owner'):
Owned.on_owner_change.send(document, previous=document._previous_owner)