【问题标题】:Python subprocess: The process cannot access the file because it is being used by another processPython子进程:该进程无法访问该文件,因为它正在被另一个进程使用
【发布时间】:2022-08-11 17:18:39
【问题描述】:

我在子进程下运行 Minecraft 服务器以使用 python 脚本中的输出。

mc_dir = \'C:\\\\Users\\\\aiche\\\\Desktop\\\\server\'
mc_start_cmd = \'java -Xms1G -Xmx1G -jar server.jar --nogui\'
server = subprocess.Popen(mc_start_cmd, shell=True, stdout=subprocess.PIPE, cwd=mc_dir)

但是当我启动服务器时,我得到了这个日志:

Starting net.minecraft.server.Main
2022-08-11 10:52:19,591 ServerMain ERROR Unable to delete file C:\\Users\\aiche\\Desktop\\server\\logs\\latest.log: java.nio.file.FileSystemException C:\\Users\\aiche\\Desktop\\server\\logs\\latest.log: The process cannot access the file because it is being used by another process
[10:52:21] [ServerMain/INFO]: Building unoptimized datafixer
[10:52:21] [ServerMain/INFO]: Environment: authHost=\'https://authserver.mojang.com/\', accountsHost=\'https://api.mojang.com/\', sessionHost=\'https://sessionserver.mojang.com/\', servicesHost=\'https://api.minecraftservices.com/\', name=\'PROD\'
[10:52:21] [ServerMain/ERROR]: Failed to start the minecraft server
java.io.IOException: The process cannot access the file because another process has locked a portion of the file
at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[?:?]
at sun.nio.ch.FileDispatcherImpl.write(FileDispatcherImpl.java:68) ~[?:?]
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:132) ~[?:?]
at sun.nio.ch.IOUtil.write(IOUtil.java:76) ~[?:?]
at sun.nio.ch.IOUtil.write(IOUtil.java:67) ~[?:?]
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:288) ~[?:?]
at alo.a(SourceFile:40) ~[server-1.19.2.jar:?]
at drq$c.<init>(SourceFile:333) ~[server-1.19.2.jar:?]
at drq.c(SourceFile:321) ~[server-1.19.2.jar:?]
at net.minecraft.server.Main.main(SourceFile:125) ~[server-1.19.2.jar:?]
at net.minecraft.bundler.Main.lambda$run$0(Main.java:54) ~[?:?]
at java.lang.Thread.run(Thread.java:833) [?:?]

为什么 server.jar 不能使用这些文件以及如何修复它?

  • 你能确认(例如使用任务管理器)没有其他 Minecraft 服务器在同一台机器上运行吗?重启机器有用吗?
  • 检查你的任务管理器,看看你是否没有在后台运行另一个我的世界服务器。此外,如果您在另一个应用程序中打开了日志文件,请关闭该应用程序。正如 Wander 所说,重新启动可能会解决它(强硬的方式)

标签: python subprocess


【解决方案1】:

我重新启动了机器,它工作得很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    相关资源
    最近更新 更多