python socket connection_Python socket.create_connection方法代码示例

本文整理汇总了Python中gevent.socket.create_connection方法的典型用法代码示例。如果您正苦于以下问题:Python socket.create_connection方法的具体用法?Python socket.create_connection怎么用?Python socket.create_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块gevent.socket的用法示例。

在下文中一共展示了socket.create_connection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: connect

​点赞 6

# 需要导入模块: from gevent import socket [as 别名]

# 或者: from gevent.socket import create_connection [as 别名]

def connect(self, address, remote_pubkey):

log.debug('connecting', address=address)

"""

gevent.socket.create_connection(address, timeout=Timeout, source_address=None)

Connect to address (a 2-tuple (host, port)) and return the socket object.

Passing the optional timeout parameter will set the timeout

getdefaulttimeout() is default

"""

try:

connection = create_connection(address, timeout=self.connect_timeout)

except socket.timeout:

log.info('connection timeout', address=address, timeout=self.connect_timeout)

self.errors.add(address, 'connection timeout')

return False

except socket.error as e:

log.info('connection error', errno=e.errno, reason=e.strerror)

self.errors.add(address, 'connection error')

return False

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值