本文整理匯總了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))