python - Python:适用于 Windows,不适用于 WSL(ubuntu):AttributeError:“LogFile”对象没有属性“fileno”-LogFile 不是我的变量
问题描述
我正在学习 asyncio、Python 和 Kivy。我的代码是从服务器进程将图像推送到多个客户端(该代码未失败,因此未包含在内)我的客户端代码提取失败,如下所示。我的客户端代码在 Windows 上运行,但不在 WSL (Ubuntu) 上。'LogFile' 不是我的代码中的变量。
运行时错误 -
Traceback (most recent call last):
File "ScrollApp_as_V3c_image.py", line 436, in <module>
loop.run_until_complete(root_func()) # worked
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "ScrollApp_as_V3c_image.py", line 330, in run_client
stdin, stdout = await aioconsole.get_standard_streams()
File "/home/gc/.local/lib/python3.8/site-packages/aioconsole/stream.py", line 179, in get_standard_streams
cache[key] = await connection
File "/home/gc/.local/lib/python3.8/site-packages/aioconsole/stream.py", line 163, in create_standard_streams
if all(map(is_pipe_transport_compatible, (stdin, stdout, stderr))):
File "/home/gc/.local/lib/python3.8/site-packages/aioconsole/stream.py", line 15, in is_pipe_transport_compatible
fileno = pipe.fileno()
AttributeError: 'LogFile' object has no attribute 'fileno'
我的代码提取 -
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.app import runTouchApp
from kivy.core.image import Image
from kivy.uix.label import Label
from kivy.app import async_runTouchApp
import aioconsole
import asyncio
import sys
import random
import os
images = 1
client_number = sys.argv[1]
print("This is client " + client_number)
async def run_client():
stdin, stdout = await aioconsole.get_standard_streams()
reader, writer = await asyncio.open_connection('127.0.0.1', 6050)
stdout.write("Client: Client connected !")
async def run_app_happily(root, other_task):
await async_runTouchApp(root, async_lib='asyncio') # run Kivy
print('App done')
# now cancel all the other tasks that may be running
other_task.cancel()
layout = GridLayout(cols=3, spacing=3, size_hint_y=None)
layout.bind(minimum_height=layout.setter('height'))
image_rows = 3
for i in range(3*image_rows):
i = random.randint(1, 10)
im = "Image" + str(i) + ".PNG"
btn = Button(background_normal = im, background_down ='Click.PNG',size_hint_y=None, height=100)
layout.add_widget(btn)
root = ScrollView(size_hint=(1, None), size=(Window.width, Window.height))
root.add_widget(layout)
if __name__ == '__main__':
def root_func():
while True:
print("In __main__")
other_task = asyncio.ensure_future(run_client())
return asyncio.gather(run_app_happily(root, other_task), other_task)
loop = asyncio.get_event_loop()
loop.run_until_complete(root_func())
loop.close()
解决方案
推荐阅读
- java - 将 JSON 数反序列化为 BigDecimal 时支持多少个小数位?
- java - 当继承策略为 InheritanceType.JOINED 时,Hibernate 使用错误的表进行连接
- android - Catalyst Instance 已经消失:由 FrescoModule 请求
- go - jaeger Observer 自定义指标,带有 prometheus 的标签
- javascript - 在 GUID Power Automate 中删除 Hypen
- algorithm - 具有特定顺序的笛卡尔积
- java - 设置 CSVSaver 实例以将 arfff 文件转换为 csv 时 Java Weka 中的 InaccessibleObjectException
- ios - 在 UIView 动画时点击它
- node.js - 在 Windows WSL2.0 上获取 SyntaxError: Unexpected token ...
- arrays - Http.Get:字符串对数组 - 类型 {string, string}[] 不可分配给类型 string[]