本文整理匯總了Python中psutil.CONN_CLOSE_WAIT屬性的典型用法代碼示例。如果您正苦於以下問題:Python psutil.CONN_CLOSE_WAIT屬性的具體用法?Python psutil.CONN_CLOSE_WAIT怎麽用?Python psutil.CONN_CLOSE_WAIT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類psutil
的用法示例。
在下文中一共展示了psutil.CONN_CLOSE_WAIT屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_tcp
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_CLOSE_WAIT [as 別名]
def test_tcp(self):
addr = ("127.0.0.1", get_free_port())
assert not thisproc.connections(kind='tcp4')
server, client = tcp_socketpair(AF_INET, addr=addr)
try:
cons = thisproc.connections(kind='tcp4')
self.assertEqual(len(cons), 2)
self.assertEqual(cons[0].status, psutil.CONN_ESTABLISHED)
self.assertEqual(cons[1].status, psutil.CONN_ESTABLISHED)
# May not be fast enough to change state so it stays
# commenteed.
# client.close()
# cons = thisproc.connections(kind='all')
# self.assertEqual(len(cons), 1)
# self.assertEqual(cons[0].status, psutil.CONN_CLOSE_WAIT)
finally:
server.close()
client.close()
示例2: assert_free_resources
# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import CONN_CLOSE_WAIT [as 別名]
def assert_free_resources():
ts = threading.enumerate()
assert len(ts) == 1, ts
p = psutil.Process()
children = p.children()
if children:
for p in children:
p.kill()
p.wait(1)
assert not children, children
cons = [x for x in p.connections('tcp')
if x.status != psutil.CONN_CLOSE_WAIT]
assert not cons, cons