def _get_ports_in_use(cls):
"""
Returns a set of ports currently used on localhost.
"""
try:
return set([x.laddr[1] for x in psutil.net_connections(kind='inet4')])
except psutil.AccessDenied:
# On some platforms (such as OS X), root privilege is required to get used ports.
# In that case we avoid port confliction to the best of our knowledge.
_logger.info('ports in use cannot be obtained on this platform; ports will be assigned sequentially')
return set()
评论列表
文章目录