Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Keyword arguments to functions in web worker are not passed properly #2398

@ttomasz

Description

@ttomasz

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help

What happened?

I tried calling a function in web worker with keyword arguments but it got stuck. It looks like keyword arguments are not passed properly between main thread and web worker and end up being passed as some kind of object as positional argument. Below I pasted example code so you can reproduce (I tested with 2025.10.3 as well with the same result).

What browsers are you seeing the problem on? (if applicable)

Firefox

Console info

This call:
`await my_worker.some_function(2, 3, 10, x=20)`

Results in:
`some_function called with a=2, b=3, args=(10, [object Object]), kwargs={}`

Additional Context

Repro:

<!doctype html>
<html>
<head>
    <!-- https://docs.pyscript.net/2025.7.1/user-guide/workers/ -->
    <script src="./mini-coi.js" scope="./"></script>
    <!-- Recommended meta tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <!-- PyScript CSS -->
    <link rel="stylesheet" href="https://pyscript.net/releases/2025.7.1/core.css">
    <!-- This script tag bootstraps PyScript -->
    <script type="module" src="https://pyscript.net/releases/2025.7.1/core.js"></script>
</head>
<body>
<py-script type="py" worker name="my-worker">
    from pyscript import window

    def some_function(a: int, b: int, *args, **kwargs) -> int:
        window.console.log(f"some_function called with a={a}, b={b}, args={args}, kwargs={kwargs}")
        return a + b
    
    __export__ = ["some_function"]
</py-script>
<py-script type="py">
from pyscript import workers
from pyscript import display

my_worker = await workers["my-worker"]

async def run(_event):
    result_positional = await my_worker.some_function(2, 3, 10, x=20)
    display(f"Result with positional arguments: {result_positional}")
    result_keyword = await my_worker.some_function(a=5, b=7, c=10)
    display(f"Result with keyword arguments: {result_keyword}")
</py-script>
<button py-click="run">Run</button>
</body>
</html>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions