本文整理汇总了Python中Utils.Utils.print_exception方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.print_exception方法的具体用法?Python Utils.print_exception怎么用?Python Utils.print_exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils.Utils
的用法示例。
在下文中一共展示了Utils.print_exception方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_poll
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_poll(self):
empty = True
with self.lock:
empty = len(self.descripters) == 0
try:
if(empty):
time.sleep(self.timeout)
return
status = self.poller.poll(self.timeout)
for fd, pollflag in status:
flag = (SocketPollFlag.Read if bool(pollflag & select.EPOLLIN) else SocketPollFlag.Zero) \
| (SocketPollFlag.Write if bool(pollflag & select.EPOLLOUT) else SocketPollFlag.Zero) \
| (SocketPollFlag.Error if bool(pollflag & select.EPOLLERR) else SocketPollFlag.Zero)
#print(' signaled fd: %d' % fd, flush=True)
fd_obj = self.fd_map[fd]
self.invoke_callback(fd_obj, flag)
except Exception as ex:
# ThreadInterruptedException
# Exception
Utils.print_exception(ex)
self.running = False
示例2: do_select
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_select(self):
empty = True
owner = self.owner
with owner.lock:
owner.read_sockets.clear()
owner.write_sockets.clear()
owner.error_sockets.clear()
owner.update_select_sockets()
empty = len(owner.read_sockets) == 0 \
and len(owner.write_sockets) == 0 \
and len(owner.error_sockets) == 0
try:
if(empty):
time.sleep(owner.timeout)
return
read, write, error = select.select(owner.read_sockets, owner.write_sockets, owner.error_sockets, owner.timeout)
for i in read:
owner.do_recv(i)
for i in write:
owner.do_send(i)
for i in error:
owner.do_error(i)
except Exception as ex:
# ThreadInterruptedException
# Exception
Utils.print_exception(ex)
示例3: main
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def main(argv):
try:
# TypeError: can't set attributes of built-in/extension type 'object'
#object.expects = MethodType(expects_type, object)
return AutoNapt.main(argv)
except Exception as ex:
Utils.print_exception(ex)
return 1
示例4: do_close
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_close(self):
#Utils.assertion(self.lock.locked(), 'need lock')
self.status = NaptSocketStatus.Closed
try:
self.socket.close() # non-blocking
except Exception as ex:
Utils.print_exception(ex)
示例5: close_server
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def close_server(self):
#if self.debug:
# print(' NaptConnection.close_server: %s' % str(self.server))
try:
self.on_server_closing(None)
except Exception as ex:
Utils.print_exception(ex)
try:
if self.server.close():
self.on_server_closed(None);
except Exception as ex:
Utils.print_exception(ex)
示例6: close_client
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def close_client(self):
#if self.debug:
# print(' NaptConnection.close_client: %s' % str(self.client))
try:
self.on_client_closing(None)
except Exception as ex:
Utils.print_exception(ex)
try:
if self.client.close():
self.on_client_closed(None)
except Exception as ex:
Utils.print_exception(ex)
示例7: connect
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def connect(self, conn, protocol):
Utils.expects_type(NaptConnection, conn, 'conn')
#Utils.expects_type(ProtocolSetting, protocol, 'protocol')
try:
status = conn.tag
addr = protocol.address
port = protocol.port
endpoint = (addr, port)
status.connecting = True
status.protocol_setting = protocol
conn.connect(endpoint) # async
except Exception as ex:
Utils.print_exception(ex)
conn.close()
示例8: do_send
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_send(self):
while True:
data = None
with self.lock:
if len(self.send_buffers) == 0:
self.is_sending = False
return
data= self.send_buffers.popleft() # Dequeue
try:
self.socket.settimeout(5.0)
self.socket.sendall(data)
except Exception as ex:
Utils.print_exception(ex)
self.do_close()
示例9: do_recv
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_recv(self, so):
Utils.expects_type(socket.socket, so, 'so')
try:
accepted, remote= so.accept();
accepted.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 0, 0))
accepted.settimeout(15.0)
e = NaptListenerEventArgs(accepted, so);
self.on_accepted(e)
except Exception as ex:
Utils.print_exception(ex)
raise ex
示例10: recv_server
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def recv_server(self):
try:
#self.client.socket.settimeout(5.0)
#self.server.socket.settimeout(5.0)
data= self.server.socket.recv(4096)
e = NaptConnectionEventArgs(self, data, 0, len(data))
if len(data) == 0: # closed
#self.close_server()
self.close()
return
#print(' DATA: %s' % str(data), flush=True)
self.on_server_recieved(e)
self.client.push(data, 0, len(data))
except Exception as ex: # SocketException
Utils.print_exception(ex)
self.close()
示例11: do_recv
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_recv(self, so):
Utils.expects_type(socket.socket, so, 'so')
try:
so.settimeout(3.0)
so_accepted, remote= so.accept();
so_accepted.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 0, 0))
e = NaptListenerEventArgs(so_accepted, so, self.port);
self.on_accepted(e)
except Exception as ex:
print('do_recv: Exception', flush=True)
Utils.print_exception(ex)
print('', flush=True)
try:
key = [k for k, v in self.sockets.items() if v == so][0]
self.remove_port(key)
except Exception as ex:
pass
示例12: do_connect
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_connect(self, e):
try:
local = e.accepter.getsockname()
port = local[1]
endpoint= None
with self.lock:
endpoint = self.map[port]
if endpoint is None:
return
so = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
so.connect(endpoint)
conn = NaptConnection(e.accepted, so);
self.relay.add_connection(conn)
except Exception as ex:
Utils.print_exception(ex)
示例13: do_connect
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
def do_connect(self, endpoint):
try:
self.server.connect(endpoint) # blocking
#self.client.socket.settimeout(5.0)
#self.server.socket.settimeout(5.0)
with self.lock:
if self.is_closed:
# todo close
return
self.is_connected = True
#print('INVOKE: on_connected')
self.on_connected(None)
except Exception as ex:
print(' endpoint: %s' % str(endpoint))
Utils.print_exception(ex)
self.close()
示例14: NaptListener
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import print_exception [as 别名]
import socket
import select
import struct
import threading
from enum import Enum
from threading import Lock
from Utils import Utils
try:
from Event2 import Event2
from SocketSelector import SocketSelector
from SocketPoller import SocketPoller, SocketPollFlag
from NaptListenerEventArgs import NaptListenerEventArgs
except Exception as ex:
Utils.print_exception(ex)
class NaptListener(object):
def __init__(self, bindaddr):
super().__init__()
self.lock = Lock()
self.bindaddr = bindaddr
self.sockets = {} # Dictionary<int, Socket>
self.status = NaptListenerStatus.Stopped
self.port = 0
self.accepted = Event2('NaptListenerEventArgs')
def __str__(self):
return 'NaptListener{ %s }' %', '.join([