本文整理匯總了Python中pydispatch.dispatcher.send方法的典型用法代碼示例。如果您正苦於以下問題:Python dispatcher.send方法的具體用法?Python dispatcher.send怎麽用?Python dispatcher.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pydispatch.dispatcher
的用法示例。
在下文中一共展示了dispatcher.send方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: stop
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def stop(self):
dispatcher.send(data = "LinkLayer stopping..", signal = LinkLayer.SIGNAL_LINKLAYER_STOPPING, sender = LinkLayer.DISPATCHER_SENDER_NAME)
self.state["EVENT_STOP_WRITE"].set()
self.state["EVENT_STOP_READ"].set()
# terminate read thread if set
if self.state.has_key("read_thread"):
try:
self.state["read_thread"].join()
except RuntimeError:
pass # same thread or not started
# terminate write thread if set
if self.state.has_key("write_thread") and threading.currentThread != self.state["write_thread"]:
try:
self.state["write_thread"].join()
except RuntimeError:
pass # same thread or not started
dispatcher.send(data = "LinkLayer stopped", signal = LinkLayer.SIGNAL_LINKLAYER_STOPPED, sender = LinkLayer.DISPATCHER_SENDER_NAME)
示例2: start
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def start(self):
#sync linklayer (Send with SEQ till correct ACK received)
self.__sync_link()
# start write thread
#thread.start_new_thread(self.write_rep, ( ))
self.state["write_thread"] = Thread(target = self.write_rep, name = "LinkLayer writer", args = ( ))
self.state["write_thread"].start()
# start read thread
#thread.start_new_thread(self.read_rep, ( ) )
self.state["read_thread"] = Thread(target = self.read_rep, name = "LinkLayer reader", args = ( ))
self.state["read_thread"].start()
dispatcher.send(data = "LinkLayer running", signal = LinkLayer.SIGNAL_LINKLAYER_STARTED, sender = LinkLayer.DISPATCHER_SENDER_NAME)
# we don't send this from __sync_link, but when write thread is started, as this is resend on reconnect request after
# write thread restart too (in difference to SIGNAL_LINK_LAYER_STARTED which is only send once)
dispatcher.send(data = "LinkLayer connection established", signal = LinkLayer.SIGNAL_LINKLAYER_CONNECTION_ESTABLISHED, sender = LinkLayer.DISPATCHER_SENDER_NAME)
示例3: print_msg
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def print_msg(class_name, method, message, level='DEBUG'):
if level.lower() != 'error' and Commons.quiet:
return
log_level = '[' + level + ']'
log_message = '{:7s} {:11s} {:35s} {!s:s}'.format(log_level, class_name, method, message)
try:
print(log_message)
Logger(log_message)
except:
print(log_message.encode('utf-8'))
if level == 'ERROR':
SIGNAL = 'publish-error-signal'
sender = {}
new_message = ''.join(str(v) for v in message)
dispatcher.send(signal=SIGNAL, sender=sender, message=new_message, class_name=class_name, method_name=method)
示例4: listen
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def listen(self):
while self._running:
socket_list = [self.serial]
read_sockets, write_sockets, error_sockets = select.select(socket_list, socket_list, [], 5)
if read_sockets:
data = self.serial.recv(1024)
if data:
self.read_data(data)
else:
LOGGER.warning('OOPS connection lost, reconnect...')
self.reconnect()
if write_sockets:
while not self.queue.empty():
data = self.queue.get()
try:
self.serial.send(data)
except OSError:
LOGGER.warning('OOPS connection lost, reconnect...')
self.reconnect()
time.sleep(0.05)
示例5: __on_reconnect
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def __on_reconnect(self):
#print "Handling reconnect..."
#print "Stop Write thread..."
dispatcher.send(data = "LinkLayer connection reset by peer", signal = LinkLayer.SIGNAL_LINKLAYER_CONNECTION_RESET, sender = LinkLayer.DISPATCHER_SENDER_NAME)
# stop write thread (we want to write from this thread on connection establishment)
self.state["EVENT_STOP_WRITE"].set() # set stop event for write thread
# wait for write thread to terminate
self.state["write_thread"].join() # wait for current write thread to terminate
#print "Write thread terminated"
# empty queues with old data
#print "Clearing input and output queues..."
self.state["qout"].queue.clear()
#self.state["qin"].queue.clear()
# write empty report in order to terminate the blocking read on other end
# (peer is waiting for incoming report after sending reconnect request, which is never
# sent after the write thread has been terminated)
outbytes = struct.pack('!BB62s', 0, 0, "" )
self.fout.write(outbytes)
self.fout.flush()
# resync connection (sync SEQ to ACK before restarting write thread)
self.__sync_link()
# restart write thread
#print "Restarting write thread..."
self.state["EVENT_STOP_WRITE"].clear()
self.state["write_thread"] = Thread(target = self.write_rep, name = "LinkLayer writer", args = ( ))
self.state["write_thread"].start()
# we don't send this after sync, but when write thread is restarted
dispatcher.send(data = "LinkLayer connection established", signal = LinkLayer.SIGNAL_LINKLAYER_CONNECTION_ESTABLISHED, sender = LinkLayer.DISPATCHER_SENDER_NAME)
示例6: __write_raw_stream
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def __write_raw_stream(self, stream):
# should keep track of LinkLayer's output queue size (needs additional dispatcher messages)
dispatcher.send(data = stream, signal = TransportLayer.SIGNAL_TRANSPORTLAYER_SEND_STREAM, sender = TransportLayer.TRANSPORTLAYER_SENDER_NAME_DOWN)
示例7: publish_changes
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def publish_changes(self, etype, echid):
"""Post updates for specified event type."""
_LOGGING.debug('%s Update: %s, %s',
self.name, etype, self.fetch_attributes(etype, echid))
signal = 'ValueChanged.{}'.format(self.cam_id)
sender = '{}.{}'.format(etype, echid)
if dispatcher:
dispatcher.send(signal=signal, sender=sender)
self._do_update_callback('{}.{}.{}'.format(self.cam_id, etype, echid))
示例8: dispatch_signal
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def dispatch_signal(signal=dispatcher.Any, sender=dispatcher.Anonymous,
*arguments, **named):
'''
Dispatch signal with exception proof
'''
LOGGER.debug('Dispatch %s', signal)
try:
dispatcher.send(signal, sender, *arguments, **named)
except Exception:
LOGGER.error('Exception dispatching signal %s', signal)
LOGGER.error(traceback.format_exc())
示例9: send_to_transport
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def send_to_transport(self, data):
if not self.connection or not self.connection.is_connected():
LOGGER.error('Not connected to zigate')
return
self.connection.send(data)
示例10: send_data
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def send_data(self, cmd, data="", wait_response=None, wait_status=True):
'''
send data through ZiGate
'''
LOGGER.debug('REQUEST : 0x{:04x} {}'.format(cmd, data))
self._last_status[cmd] = None
if wait_response:
self._clear_response(wait_response)
if isinstance(cmd, int):
byte_cmd = struct.pack('!H', cmd)
elif isinstance(data, str):
byte_cmd = bytes.fromhex(cmd)
else:
byte_cmd = cmd
if isinstance(data, str):
byte_data = bytes.fromhex(data)
else:
byte_data = data
assert type(byte_cmd) == bytes
assert type(byte_data) == bytes
length = len(byte_data)
byte_length = struct.pack('!H', length)
checksum = self.checksum(byte_cmd, byte_length, byte_data)
msg = struct.pack('!HHB%ds' % length, cmd, length, checksum, byte_data)
LOGGER.debug('Msg to send %s', hexlify(msg))
enc_msg = self.zigate_encode(msg)
enc_msg.insert(0, 0x01)
enc_msg.append(0x03)
encoded_output = bytes(enc_msg)
LOGGER.debug('Encoded Msg to send %s', hexlify(encoded_output))
self.send_to_transport(encoded_output)
if wait_status:
status = self._wait_status(cmd)
if wait_response and status is not None:
r = self._wait_response(wait_response)
return r
return status
return False
示例11: identify_device
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def identify_device(self, time_sec=5):
'''
send identify command
sec is time in second
'''
ep = list(self.endpoints.keys())
ep.sort()
if ep:
endpoint = ep[0]
else:
endpoint = 1
self._zigate.identify_send(self.addr, endpoint, time_sec)
示例12: send
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def send(self, data):
self.queue.put(data)
示例13: reconnect
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def reconnect(self, retry=True):
delay = 1
while self._running:
try:
if self.serial:
self.serial.close() # just to be sure it's not already open
self.serial = self.initSerial()
break
except ZIGATE_NOT_FOUND:
LOGGER.error('ZiGate has not been found, please check configuration.')
if not retry:
sys.exit(2)
except Exception:
if not retry:
LOGGER.error('Cannot connect to ZiGate using port {}'.format(self._port))
raise ZIGATE_CANNOT_CONNECT('Cannot connect to ZiGate using port {}'.format(self._port))
sys.exit(2)
# maybe port has change so try to find it
if delay > 3:
self._port = 'auto'
msg = 'Failed to connect, retry in {} sec...'.format(int(delay))
dispatcher.send(ZIGATE_FAILED_TO_CONNECT, message=msg)
LOGGER.error(msg)
time.sleep(int(delay))
if delay < 30:
delay *= 1.5
示例14: do_GET
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def do_GET(self):
# get the requested path and the client IP
resource = self.path
clientIP = self.client_address[0]
sessionID = None
cookie = self.headers.getheader("Cookie")
if cookie:
# search for a SESSIONID value in the cookie
parts = cookie.split(";")
for part in parts:
if "SESSIONID" in part:
# extract the sessionID value
name, sessionID = part.split("=")
# fire off an event for this GET (for logging)
dispatcher.send("[*] "+resource+" requested from "+str(sessionID)+" at "+clientIP, sender="HttpHandler")
# get the appropriate response from the agent handler
(code, responsedata) = self.server.agents.process_get(self.server.server_port, clientIP, sessionID, resource)
# write the response out
self.send_response(code)
self.end_headers()
self.wfile.write(responsedata)
self.wfile.flush()
# self.wfile.close() # causes an error with HTTP comms
示例15: do_POST
# 需要導入模塊: from pydispatch import dispatcher [as 別名]
# 或者: from pydispatch.dispatcher import send [as 別名]
def do_POST(self):
resource = self.path
clientIP = self.client_address[0]
sessionID = None
cookie = self.headers.getheader("Cookie")
if cookie:
# search for a SESSIONID value in the cookie
parts = cookie.split(";")
for part in parts:
if "SESSIONID" in part:
# extract the sessionID value
name, sessionID = part.split("=")
# fire off an event for this POST (for logging)
dispatcher.send("[*] Post to "+resource+" from "+str(sessionID)+" at "+clientIP, sender="HttpHandler")
# read in the length of the POST data
if self.headers.getheader('content-length'):
length = int(self.headers.getheader('content-length'))
postData = self.rfile.read(length)
# get the appropriate response for this agent
(code, responsedata) = self.server.agents.process_post(self.server.server_port, clientIP, sessionID, resource, postData)
# write the response out
self.send_response(code)
self.end_headers()
self.wfile.write(responsedata)
self.wfile.flush()
# self.wfile.close() # causes an error with HTTP comms
# supress all the stupid default stdout/stderr output