python - 使用多处理时,输入函数在 python 中过早结束
问题描述
我有一些这样的代码:
from multiprocessing import Process
def foo():
while True:
f=input('Input: ')
print('Why doesn't this print?')
if __name__=='__main__':
p1 = Process(target=bruh)
print('this prints')
p1.start()
print('and so does this')
但是运行时,我收到此错误:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python38-32\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Program Files (x86)\Python38-32\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\(myUsername)\Desktop\program.py", line 739, in foo
f=input('still running')
EOFError: EOF when reading a line
我相信这是因为进程在到达输入函数时结束,导致它给出字段结束错误,但我不知道。请帮忙!
(使用python 3.8.3)
解决方案
EOF 错误通常是由行尾的错误引起的,例如缺少括号或类似的东西。尝试将 if 缩进到函数内部的循环中。
如果这不起作用,也许你写print('Why doesn't this print?')
而不是print("Why doesn't this print?")
推荐阅读
- python - Python CSV如何删除第一行数据?
- php - 如何向 request()->all() 添加变量?(Laravel 6.0)
- javascript - v-for 渲染组件和
,如何只为一个组件实例更改它 - c# - 如何使用 Xamarin 在 iOS 13 中获取设备令牌?
- mongodb - 您如何对聚合管道的输出进行分页?
- php - 如何使用 PHP SDK v2 从 aws s3 headObject 读取结果?
- angular - 为什么我得到 TypeError system.config is not a function?
- react-native - React Native 为什么每次点击 textInput 时我的键盘都会立即消失?
- azure - 如何使用 terraform 在虚拟机中启用 Azure Monitor?
- ios - Xcode 11 没有与 iOS 13 同时发布?