windows环境下,start命令可以启动其他进程,且不会阻塞当前进程
import os
cmd = 'start python E:\test\test.py'
os.system(cmd)
根据进程id关闭进程:
cmd = 'taskkill /pid ' + str(pid) + ' /f'
os.system(cmd)
获取外网ip:
ip = requests.get('http://ifconfig.me/ip', timeout=3).text.strip()
获取内网ip:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('8.8.8.8', 80))
_ip = s.getsockname()[0]
except Exception as e:
print('get ip error: ', e)
finally:
s.close()