flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.61k stars 455 forks source link

BrokenPipeError: [Errno 32] Broken pipe #2917

Open burhansvural opened 8 months ago

burhansvural commented 8 months ago

I get this error when I close the page by clicking on the close icon.

import flet as ft
dosya = open("urun.txt", "a")

def main2(page: ft.Page):

    txt_urad = ft.Text("Ürün Adı", width=120)
    txt_fld_urad = ft.TextField(autofocus=True, expand=True)
    row_urad = ft.Row(controls=[txt_urad, txt_fld_urad], width=float("inf"))

    txt_fyt = ft.Text("Ürün Fiyatı", width=120)
    txt_fld_fyt = ft.TextField(expand=True)
    row_urfyt = ft.Row(controls=[txt_fyt, txt_fld_fyt], width=float("inf"))

    lstview = ft.ListView(
        height=float("inf"),
        spacing=10,
        padding=3,
        auto_scroll=True,
    )

    def kaydet(e):
        global dosya
        dosya.write(f"{txt_fld_urad.value},{txt_fld_fyt.value}\n")
        dosya.flush()
        page.update()

    def cikis(e):
        print("cikis metodu calisti...")
        global dosya
        dosya.close()
        page.window_close()

    def lstview_ekle(e):
        pass

    btn_kaydet = ft.ElevatedButton(text="KAYDET", on_click=kaydet,
                                   style=ft.ButtonStyle(shape={"": ft.RoundedRectangleBorder(radius=10)}),
                                   bgcolor=ft.colors.SURFACE_VARIANT)
    btn_cikis = ft.ElevatedButton(text="ÇIKIŞ", on_click=cikis)
    row_btn = ft.Row(controls=[btn_kaydet, btn_cikis], width=float("inf"), alignment=ft.MainAxisAlignment.END)

    page.add(
        row_urad,
        row_urfyt,
        row_btn,
        lstview
    )

    page.window_always_on_top = True

    page.update()

ft.app(target=main2, name="main2", port=5555)

Error output Traceback (most recent call last): File "/xxx/xxy/main2.py", line 55, in ft.app(target=main2, name="main2", port=5555) File "/xxx/xxs/python312-venv/lib/python3.12/site-packages/flet_runtime/app.py", line 70, in app return asyncio.run( ^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/xxx/xxx/python312-venv/lib/python3.12/site-packages/flet_runtime/app.py", line 199, in app_async on_app_startup(conn.page_url) File "/xxx/xxx/python312-venv/lib/python3.12/site-packages/flet_runtime/app.py", line 131, in on_app_startup print(url_prefix, page_url) BrokenPipeError: [Errno 32] Broken pipe

OS and Flet Version Os: Debian 12 Flet Version: 0.21.2 Python Version: 3.12.2

akunzz commented 8 months ago

try with python 3.11.6