Python os.listdir在后台时抛出错误5(IO错误)
我目前正在为VK社交网络编写一个基于插件的服务器。插件系统是YAPSY,并且该过程正在使用Python os.listdir在后台时抛出错误5(IO错误),python,linux,fork,listdir,Python,Linux,Fork,Listdir,我目前正在为VK社交网络编写一个基于插件的服务器。插件系统是YAPSY,并且该过程正在使用os.fork()进行后台处理 我已经为上述服务器编写了一个文件服务器插件。在我启动它之后,它可以正常工作,但是当我关闭用于启动它的终端会话(我以root用户身份运行它)时,用于返回文件/文件夹列表的LIST命令开始抛出[Errno 5]输入/输出错误 我使用os.listdir获取文件夹内容,如下所示: elif cmd == u'list': flist = os.listdir
os.fork()
进行后台处理
我已经为上述服务器编写了一个文件服务器插件。在我启动它之后,它可以正常工作,但是当我关闭用于启动它的终端会话(我以root用户身份运行它)时,用于返回文件/文件夹列表的LIST
命令开始抛出[Errno 5]输入/输出错误
我使用os.listdir
获取文件夹内容,如下所示:
elif cmd == u'list':
flist = os.listdir(self.cwd+'/'+('' if len(args)==0 else args[0]))
otp = "Listing of "+(self.cwd.replace(self.topdirpath, "<root>") if len(args) == 0 else self.cwd.replace(self.topdirpath, "<root>")+"/"+args[0])+':\n'
num = 0
flist.sort()
for fi in flist:
otp += "["+str(num)+"] "+('-DIR- ' if os.path.isdir(self.cwd+'/'+('' if len(args)==0 else args[0])+'/'+fi) else '')+str(fi)+"\n"
num += 1
self.fSay(otp,vk,'200 LIST OK')
return True
elif cmd==u'list':
flist=os.listdir(self.cwd+'/'+(''如果len(args)==0,其他args[0]))
otp=“如果len(args)=0,则列出“+(self.cwd.replace(self.topdirpath)”+”/“+args[0])+”:\n”
num=0
flist.sort()
对于flist中的fi:
otp+=“[”+str(num)+“]”+('-DIR-'如果os.path.isdir(self.cwd++'/'++)(''如果len(args)==0其他args[0])+'/'+fi其他“”)+str(fi)+“\n”
num+=1
self.fSay(otp,vk,'200列表正常')
返回真值
()
虽然我没有关闭启动服务器的SSH会话,但它工作正常:
>> #$list
<< Listing of <root>:
[0] -DIR- AniArt
[1] -DIR- gifs
[2] -DIR- inbox
>#$list
>#$list
显然,它与print
命令有关
我的服务器使用fSay
发送给我的所有内容也都转到了fLog
。将print
包装在fLog
中可以消除所有问题
有时候事情会变得很奇怪
>> #$list
<< libakcore longpoll server
There was an error processing your request. More info:
[Errno 5] Input/output error