本文整理汇总了Python中socket.EBADF属性的典型用法代码示例。如果您正苦于以下问题:Python socket.EBADF属性的具体用法?Python socket.EBADF怎么用?Python socket.EBADF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.EBADF属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EBADF [as 别名]
def run(self):
while not self.zc.done:
with self.condition:
rs = self.readers.keys()
if len(rs) == 0:
# No sockets to manage, but we wait for the timeout
# or addition of a socket
self.condition.wait(self.timeout)
if len(rs) != 0:
try:
rr, wr, er = select.select(rs, [], [], self.timeout)
if not self.zc.done:
for socket_ in rr:
reader = self.readers.get(socket_)
if reader:
reader.handle_read(socket_)
except (select.error, socket.error) as e:
# If the socket was closed by another thread, during
# shutdown, ignore it and exit
if e.args[0] != socket.EBADF or not self.zc.done:
raise
示例2: close
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EBADF [as 别名]
def close(self):
if hasattr(self.socket, '_sock'):
try:
self.socket._sock.close()
except socket.error:
info = sys.exc_info()
if info[1].args[0] != socket.EBADF:
raise info[1]
else:
pass
self.socket.close()
# Monolithic build...end of module: rocket/connection.py
# Monolithic build...start of module: rocket/filelike.py
# Import System Modules
示例3: run
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EBADF [as 别名]
def run(self):
while not self.zc.done:
with self.condition:
rs = self.readers.keys()
if len(rs) == 0:
# No sockets to manage, but we wait for the timeout
# or addition of a socket
self.condition.wait(self.timeout)
if len(rs) != 0:
try:
rr, wr, er = select.select(rs, [], [], self.timeout)
if not self.zc.done:
for socket_ in rr:
reader = self.readers.get(socket_)
if reader:
reader.handle_read(socket_)
except socket.error as e:
# If the socket was closed by another thread, during
# shutdown, ignore it and exit
if e.errno != socket.EBADF or not self.zc.done:
raise
示例4: shutdown
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EBADF [as 别名]
def shutdown(self):
if not self._is_live:
return
self._is_live = False
for connection in list(self._map.values()):
try:
connection.close(HazelcastError("Client is shutting down"))
except OSError as connection:
if connection.args[0] == socket.EBADF:
pass
else:
raise
self._map.clear()
self._thread.join()
示例5: run
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EBADF [as 别名]
def run(self):
while not globals()['_GLOBAL_DONE']:
rs = self.getReaders()
if len(rs) == 0:
# No sockets to manage, but we wait for the timeout
# or addition of a socket
#
self.condition.acquire()
self.condition.wait(self.timeout)
self.condition.release()
else:
try:
rr, wr, er = select.select(rs, [], [], self.timeout)
for socket in rr:
try:
self.readers[socket].handle_read()
except socket.error, e:
if e == socket.EBADF:
## what should I do here?
# data, (addr, port) = self.zeroconf.socket.recvfrom(_MAX_MSG_ABSOLUTE)
# File "C:\Python24\lib\socket.py", line 144, in _dummy
# raise error(EBADF, 'Bad file descriptor')
# error: (9, 'Bad file descriptor')
pass
else:
traceback.print_exc()
except:
traceback.print_exc()
except:
示例6: _forwarder
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EBADF [as 别名]
def _forwarder(chan, sock):
# Bidirectionally forward data between a socket and a Paramiko channel.
try:
while True:
r, w, x = select.select([sock, chan], [], [], 1)
if sock in r:
data = sock.recv(1024)
if len(data) == 0:
break
chan.sendall(data)
if chan in r:
data = chan.recv(1024)
if len(data) == 0:
break
sock.sendall(data)
except socket.error as e:
#Sockets return bad file descriptor if closed.
#Maybe there is a cleaner way of doing this?
if e.errno not in (socket.EBADF, errno.ECONNRESET):
raise
except select.error as e:
if e[0] != socket.EBADF:
raise
try:
chan.close()
except socket.error:
pass
try:
sock.close()
except socket.error:
pass
示例7: connect
# 需要导入模块: import socket [as 别名]
# 或者: from socket import EBADF [as 别名]
def connect(self):
def listener_thread_main(thead_sock, callback, *a, **kw):
try:
while True:
selsockets = select.select([thead_sock], [], [], 1)
if thead_sock in selsockets[0]:
callback(thead_sock, *a, **kw)
except socket.error as e:
#Sockets return bad file descriptor if closed.
#Maybe there is a cleaner way of doing this?
if e.errno != socket.EBADF:
raise
except select.error as e:
if e[0] != socket.EBADF:
raise
listening_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listening_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listening_socket.bind((self.bind_host, self.bind_port))
listening_socket.listen(1)
def accept(listen_sock, transport, remote_addr):
accept_sock, local_peer = listen_sock.accept()
channel = self.get_channel(transport, remote_addr, local_peer)
handler = ThreadHandler('fwd', _forwarder, channel, accept_sock)
self.sockets.append(accept_sock)
self.channels.append(channel)
self.threads.append(handler)
self.sockets = []
self.channels = []
self.threads = []
self.listening_socket = listening_socket
self.listening_thread = ThreadHandler('local_bind', listener_thread_main,
listening_socket, accept,
connections[env.host_string].get_transport(),
(self.remote_host, self.remote_port))