没有合适的资源?快使用搜索试试~ 我知道了~
首页求解报错:AttributeError:module ‘os’ has no attribute ‘exit’
python3 server.py 127.0.0.1 8888 Traceback (most recent call last): File “server.py”, line 83, in main() File “server.py”, line 76, in main os.exit() AttributeError: module ‘os’ has no attribute ‘exit’ 部分代码入下: from socket import * import sys,os #实现登录 def do_login(s,user,name,addr): for i in user: i
资源详情
资源评论
资源推荐

求解报错:求解报错:AttributeError:module ‘os’ has no attribute
‘exit’
python3 server.py 127.0.0.1 8888
Traceback (most recent call last):
File “server.py”, line 83, in
main()
File “server.py”, line 76, in main
os.exit()
AttributeError: module ‘os’ has no attribute ‘exit’
部分代码入下:
from socket import *
import sys,os
#实现登录
def do_login(s,user,name,addr):
for i in user:
if i == name or name == ‘管理员’:
s.sendto(“该用户已存在,请重新输入”.encode(),
addr)
return
s.sendto(b’ok’,addr)
msg = “欢迎 %s 进入聊天室” % name
#通知所有人
for i in user:
s.sendto(msg.encode(),user[i])
user[name] = addr
return
#子进程处理客户端请求
def do_chile(s):
#字典用来存储用户信息
user = {}
#循环接收请求
while True:
msg,addr = s.recvfrom(1024)
msg = msg.decode()
cmd = msg.split(’ ‘)
if cmd[0] == ‘L’:
do_login(s,user,cmd[1],addr)
#elif msg == 聊天:
do_chart()
#elif msg == 退出:
do_logout()
else:
s.sendto(“请求错误”.encode())
#发送管理员消息
def do_parent():
print(“这是父进程”)
while True:
pass
def main():
if len(sys.argv) < 3:
print(“argv is error”)
return
HOST = sys.argv[1] PORT = int(sys.argv[2])
ADDR = (HOST,PORT)
#使用数据报套接字
s = socket(AF_INET,SOCK_DGRAM)
s.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
s.bind(ADDR)
pid1 = os.fork()
if pid1 < 0:
print("创建一级子进程失败")



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0