flet icon indicating copy to clipboard operation
flet copied to clipboard

When I run the program to start the application, I get an Exception in thread Thread-1

Open jaluscg opened this issue 2 years ago • 3 comments

Description

I tried running a file that uses flet, but when I run it, I get: "Exception in thread Thread-1 (__connection_loop): Traceback (most recent call last). " I tried following the recommendations I found on Stack Overflow to install PyCharm, but the same problem keeps appearing.

Code example to reproduce the issue:

import flet as ft
import flet.canvas as cv


class State:
    x: float
    y: float

state = State()

def main(page: ft.Page):
    page.title = "Flet Brush"

    def pan_start(e: ft.DragStartEvent):
        state.x = e.local_x
        state.y = e.local_y

    def pan_update(e: ft.DragUpdateEvent):
        cp.shapes.append(
            cv.Line(
                state.x, state.y, e.local_x, e.local_y, paint= ft.Paint(stroke_width=3)
            )
        )
        cp.update()
        state.x = e.local_x
        state.y = e.local_y
    
    cp = cv.Canvas(
        [
            cv.Fill(
                ft.Paint(
                    gradient=ft.PaintLinearGradient(
                        (0, 0), (600, 600), colors=[ft.colors.CYAN_50, ft.colors.GREY]
                    )
                )
        
            )
        ],

        content = ft.GestureDetector(
            on_pan_start=pan_start,
            on_pan_update=pan_update,
            drag_interval=10,
        ),
        expand=False,
    )

    page.add(
        ft.Container(
            cp,
            border_radius=5,
            width=float("inf"),
            expand=True,
        )
    )

ft.app(main)

Describe the results you received: (venv3) Admin@DESKTOP-9H96SAC MINGW64 /e/one drive/OneDrive - Universidad Nacional de Colombia/python/ParaInformalesFlet $ "e:/one drive/OneDrive - Universidad Nacional de Colombia/python/ParaInformalesFlet/venv3/Scripts/python.exe" "e:/one drive/OneDrive - Universidad Nacional de Colombia/python/ParaInformalesFlet/counter.py" Exception in thread Thread-1 (__connection_loop): Traceback (most recent call last):

image

Describe the results you expected:

image

Additional information you deem important (e.g. issue happens only occasionally):

Flet version (pip show flet):

(Version: 0.7.4)

Operating system:

Windows

Additional environment details:

jaluscg avatar Jun 21 '23 19:06 jaluscg

When I debug the file with pdb, this appears to me: (venv3) E:\one drive\OneDrive - Universidad Nacional de Colombia\python\ParaInformalesFlet>python -m pdb counter.py

e:\one drive\onedrive - universidad nacional de colombia\python\parainformalesflet\counter.py(1)() -> import flet as ft (Pdb) (Pdb) n e:\one drive\onedrive - universidad nacional de colombia\python\parainformalesflet\counter.py(2)() -> import flet.canvas as cv (Pdb) e:\one drive\onedrive - universidad nacional de colombia\python\parainformalesflet\counter.py(5)() -> class State: (Pdb) n e:\one drive\onedrive - universidad nacional de colombia\python\parainformalesflet\counter.py(9)() -> state = State() (Pdb) n e:\one drive\onedrive - universidad nacional de colombia\python\parainformalesflet\counter.py(11)() -> def main(page: ft.Page): (Pdb) n e:\one drive\onedrive - universidad nacional de colombia\python\parainformalesflet\counter.py(57)() -> ft.app(main) (Pdb) n Exception in thread Thread-1 (__connection_loop): Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner self.run() File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "E:\one drive\OneDrive - Universidad Nacional de Colombia\python\ParaInformalesFlet\venv3\Lib\site-packages\flet\sync_local_socket_connection.py", line 143, in __connection_loop self.__connection, client_address = self.__sock.accept() ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\socket.py", line 294, in accept fd, addr = self._accept() ^^^^^^^^^^^^^^ OSError: [WinError 10038] Se intentó realizar una operación en un elemento que no es un socket --Return-- e:\one drive\onedrive - universidad nacional de colombia\python\parainformalesflet\counter.py(57)()->None -> ft.app(main) (Pdb)

jaluscg avatar Jun 21 '23 21:06 jaluscg

It tells me that it's an error because an operation is being performed on an element that is not a socket, which occurs on line 143 of the 'sync_local_socket_connection.py' file in the flet module.

jaluscg avatar Jun 21 '23 22:06 jaluscg

Your code works with the latest Flet version. Can you give it another try?

ndonkoHenri avatar Jun 23 '24 23:06 ndonkoHenri