python - Python子进程进程Popen在一段时间后暂停
问题描述
所以我有一些代码可以运行我的 Minecraft 服务器并使用子进程获取日志,但是在运行一段时间后,它会出现一些无法删除文件错误,服务器和程序继续运行,但不和谐机器人死了,它暂停收听过程。
@bot.event
async def on_ready():
channel = bot.get_channel(895697946887200818)
process = subprocess.Popen("start.bat", stdout=subprocess.PIPE)
text = ""
ready = False
for c in iter(lambda: process.stdout.read(1), b''): # replace '' with b'' for Python 3
if not ready:
if c.decode("utf-8") != "":
if c.decode("utf-8") == "\n":
if text.strip() != "":
print(text)
if '[Server thread/INFO]: Done' in text.strip():
await channel.send("server is ready!")
ready = True
text = ""
else:
text += c.decode("utf-8")
else:
if c.decode("utf-8") != "":
if c.decode("utf-8") == "\n":
if text.strip() != "":
await channel.send(text)
text = ""
else:
text += c.decode("utf-8")
这是错误
C:\Users\colin\OneDrive\Desktop\spigot 1.17>java -Xmx4096M -Xms2048M -jar spigot-1.17.1.jar nogui
Loading libraries, please wait...
2021-10-07 18:57:58,810 main ERROR Unable to delete file C:\Users\colin\OneDrive\Desktop\spigot 1.17\logs\latest.log: java.nio.file.FileSystemException C:\Users\colin\OneDrive\Desktop\spigot 1.17\logs\latest.log: The process cannot access the file because it is being used by another process
[18:58:03] [main/INFO]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD'
[18:58:04] [main/FATAL]: 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:285) ~[?:?]
at net.minecraft.util.SessionLock.a(SourceFile:40) ~[spigot-1.17.1.jar:3246-Spigot-6c1c1b2-dc764e7]
at net.minecraft.world.level.storage.Convertable$ConversionSession.<init>(Convertable.java:341) ~[spigot-1.17.1.jar:3246-Spigot-6c1c1b2-dc764e7]
at net.minecraft.world.level.storage.Convertable.c(Convertable.java:311) ~[spigot-1.17.1.jar:3246-Spigot-6c1c1b2-dc764e7]
at net.minecraft.server.Main.main(Main.java:142) [spigot-1.17.1.jar:3246-Spigot-6c1c1b2-dc764e7]
at org.bukkit.craftbukkit.Main.main(Main.java:206) [spigot-1.17.1.jar:3246-Spigot-6c1c1b2-dc764e7]
C:\Users\colin\OneDrive\Desktop\spigot 1.17>pause
此时它仍在运行,即使在最后一个错误行之后。C:\Users\colin\OneDrive\Desktop\spigot 1.17>暂停
解决方案
推荐阅读
- postgresql - PostgreSQL - 函数 concat_ws(未知,字符变化,字符变化)不存在
- java - 如何使用 AWS S3 Android 恢复上传
- mysql - MySQL:如何加快获取大量数据并使用 LIKE 的查询
- ionic-framework - 我无法在 ionic 3 中打开 pdf 文件
- queue - 在容器托管线程之间共享 LinkedBlockingQueue
- android - 向 SQLite 添加数据时为空
- javascript - 使用大量内容可编辑 div 时,Angular 6/Ionic 4 PWA 的性能下降
- python - 为什么 time.process_time() 和 time.perf_counter() 返回如此不同的值?
- python - 如何在 Python 中将 CTRL-P 发送到 Web 浏览器
- c# - 如何使用 iText 7 设置卢布符号?