首页 > 解决方案 > 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()

标签: pythonpython-asynciokivy-language

解决方案


推荐阅读