<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[OSError: [Errno 39] Directory not empty]]></title><description><![CDATA[<p dir="auto">西工大集群环境问题： OSError: [Errno 39] Directory not empty</p>
<p dir="auto">解决方法：将镜像源码中shutil.rmtree(tmp_dir)命令注释， 不让删除临时目录， 然后重新生成新镜像；</p>
<p dir="auto">这个错误一般出现在 nfs 文件系统中，本人在用 flask 写了一个文件下载程序，在下载完成之后，会有一步删除临时文件，该临时文件所在的文件系统为 nfs，于是就遇到了如上错误。经过查阅资料发现，这是 nfs 系统引起的。在打开一个文件时，nfs 文件系统会在文件所在的目录生成一个 .nfs 文件，如果有文件描述符为关闭，这时去删除文件所在的目录，就会发生如上错误。</p>
<p dir="auto">我当时调用的是 flask 的 send_file 函数来实现文件下载的。</p>
<p dir="auto">try:<br />
response = make_response(send_file(os.path.join(tmp_dir,file_name)))<br />
response.headers["Content-Disposition"] = "attachment;filename=%s"%file_name<br />
return response<br />
finally:<br />
shutil.rmtree(tmp_dir)</p>
<p dir="auto">我觉得，在我删除文件时， send_file 函数未释放打开的文件描述符，所以会报如上错误。<br />
可以选择在 shutil.rmtree(os.path.join(tmp_dir),ignore_errors=True) 或</p>
<p dir="auto">commands.getstatusoutput("rm -rf %s" % tmp_dir) 来忽略错误，但是无论哪种方法，如果文件描述符未关闭，此文件所在的文件夹都是无法删掉的。<br />
参考：</p>
<p dir="auto"><a href="http://stackoverflow.com/questions/11228079/python-remove-directory-error-file-exists" rel="nofollow ugc">http://stackoverflow.com/questions/11228079/python-remove-directory-error-file-exists</a></p>
<p dir="auto"><a href="https://github.com/hashdist/hashdist/issues/113" rel="nofollow ugc">https://github.com/hashdist/hashdist/issues/113</a><br />
————————————————<br />
版权声明：本文为CSDN博主「那时的风儿」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。<br />
原文链接：<a href="https://blog.csdn.net/lixingdefengzi/article/details/52637964" rel="nofollow ugc">https://blog.csdn.net/lixingdefengzi/article/details/52637964</a></p>
]]></description><link>http://an.forum.genostack.com/topic/245/oserror-errno-39-directory-not-empty</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 17:28:31 GMT</lastBuildDate><atom:link href="http://an.forum.genostack.com/topic/245.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 15 Mar 2021 01:26:54 GMT</pubDate><ttl>60</ttl></channel></rss>