我最近一直在体验我的脚本奇怪的行为。我在python中有一个脚本,它通过TCP/IP
接受请求并复制文件,启动/停止JAVA
应用程序等等。
一次,当必须重新创建目录的命令到来时,python AND所有JAVA
应用程序都与IOError
崩溃。
我不明白的是,在从A到B的复制过程中,它会抛出某个文件在目的地(B)中不存在的错误 - 当然!那就是我想把它复制到那里的原因!
与此同时,所有java应用程序也崩溃了IOException
。
这是堆栈跟踪:
PYTHON
Traceback (most recent call last):
File "/home/hosting/Executable.py", line 35, in copyCachedExec
copy_tree(path + "/server", target)
File "/usr/lib/python2.7/distutils/dir_util.py", line 163, in copy_tree
verbose=verbose, dry_run=dry_run))
File "/usr/lib/python2.7/distutils/dir_util.py", line 167, in copy_tree
dry_run=dry_run)
File "/usr/lib/python2.7/distutils/file_util.py", line 148, in copy_file
_copy_file_contents(src, dst)
File "/usr/lib/python2.7/distutils/file_util.py", line 44, in _copy_file_contents
fdst = open(dst, 'wb')
IOError: [Errno 2] No such file or directory: '/home/hosting/servers/22842/mods/Factorization-0.7.21.jar'
JAVA
2013-10-20 17:44:19 [SEVERE] null
java.io.IOException: Input/output error
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:272)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at java.io.FilterInputStream.read(FilterInputStream.java:83)
at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader$1.read(ConsoleReader.java:167)
at org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:267)
at org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:204)
at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readCharacter(ConsoleReader.java:995)
at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readLine(ConsoleReader.java:1167)
at net.minecraft.server.v1_5_R3.ThreadCommandReader.run(ThreadCommandReader.java:31)
P.S。:在复制开始之前删除目标目录。
编辑: 我正在复制目录树 x
/home/hosting/files/x/server.jar
/home/hosting/files/x/Factorization-0.7.21.jar
/home/hosting/files/x/other_files
到另一个目录/home/hosting/servers/22842
,它存在
答案 0 :(得分:2)
你的P.S.解释了这个问题。
open(dst, 'wb') # dst='/home/hosting/servers/22842/mods/Factorization-0.7.21.jar'
需要存在路径/home/hosting/servers/22842/mods/
。使用open()
创建文件时,如果路径的任何部分缺失,则会引发IOError
。