Skip to content

page.run_thread does not receive kwargs #5318

Closed
@python-and-novella

Description

@python-and-novella

Duplicate Check

Describe the bug

page.run_thread does not receive kwargs, but page.run_task receives.

Code sample

Code
import flet as ft
import asyncio
import time
from datetime import datetime

async def main(page: ft.Page):
    page.add(
        text := ft.Text(f'{datetime.now()}'),
        text2 := ft.Text(f'{datetime.now()}')
    )
    async def update_time(name=None,*,end=''):
        while True:
            text.value = f'{name} is {datetime.now()} {end}'
            text.update()
            await asyncio.sleep(1)
            
    page.run_task(update_time,'Time',end='.')
    
    def update_time_sync(name=None,*,end=''):
        while True:
            text2.value = f'{name} is {datetime.now()} {end}'
            text2.update()
            time.sleep(1)
            
    page.run_thread(update_time_sync,'Time',end='.')

    
ft.app(target=main)

To reproduce

Just run it.

Expected behavior

Both of them should work well, but only run_task works well.

Screenshots / Videos

Captures

Image

Image

Operating System

Windows

Operating system details

Windows 10 LTSC 2021

Flet version

0.28.2

Regression

I'm not sure / I don't know

Suggestions

Line 903 in flet/core/page.py should be:

def __context_wrapper(self, handler: Callable[..., Any]) -> Wrapper:
        def wrapper(*args,**kwargs):
            _session_page.set(self)
            handler(*args,**kwargs)

Logs

Logs
Future exception was never retrieved
future: <Future finished exception=TypeError("Page.__context_wrapper.<locals>.wrapper() got an unexpected keyword argument 'end'")>
Traceback (most recent call last):
  File "D:\Programs\Python\Python312\Lib\concurrent\futures\thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Page.__context_wrapper.<locals>.wrapper() got an unexpected keyword argument 'end'

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions