Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Functional Interface generates two sessions #651

Open
3 tasks done
noppelmax opened this issue Nov 15, 2024 · 1 comment
Open
3 tasks done

BUG: Functional Interface generates two sessions #651

noppelmax opened this issue Nov 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@noppelmax
Copy link

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pytask.
  • (optional) I have confirmed this bug exists on the main branch of pytask.

Hey,

I again tried to use the functional interface. Actually, I wanted to use pytask for the very same task as last time when I failed to get it working with pytask (#625). I tested the latest version from pip (5.1.0) and today's main branch (https://github.com/pytask-dev/pytask/tree/5804f526e01ed1d7a262a43a0dbff8d9aed06e15) with the following code from https://pytask-dev.readthedocs.io/en/stable/how_to_guides/functional_interface.html:

from pathlib import Path
from typing import Annotated

import pytask
from pytask import task


def task_create_first_file() -> Annotated[str, Path("first.txt")]:
    return "Hello, "


task_create_second_file = task(
    name="task_create_second_file", produces=Path("second.txt")
)(lambda *x: "World!")


def task_merge_files(
    first: Path = Path("first.txt"), second: Path = Path("second.txt")
) -> Annotated[str, Path("hello_world.txt")]:
    return first.read_text() + second.read_text()

session = pytask.build(
    tasks=[task_create_first_file, task_merge_files, task_create_second_file]
)

And I got the following result:

(bestofbothworlds) mnoppel@gpu08:~/bestofbothworlds$ python demo.py 
───────────────────────────────────────────── Start pytask session ─────────────────────────────────────────────
Platform: linux -- Python 3.11.7, pytask 0.5.2.dev13+g5804f52, pluggy 1.5.0
Root: /home/i56/mnoppel/bestofbothworlds
Configuration: /home/i56/mnoppel/bestofbothworlds/pyproject.toml
Plugins: pytask_parallel-0.5.0
/home/i56/mnoppel/bestofbothworlds
───────────────────────────────────────────── Start pytask session ─────────────────────────────────────────────
Platform: linux -- Python 3.11.7, pytask 0.5.2.dev13+g5804f52, pluggy 1.5.0
Root: /home/i56/mnoppel/bestofbothworlds
Configuration: /home/i56/mnoppel/bestofbothworlds/pyproject.toml
Plugins: pytask_parallel-0.5.0
Exit: pytask tried to launch a second live display which is impossible. the issue occurs when you use pytask on 
the command line on a task module that uses the programmatic interface of pytask at the same time. Use either 
the command line or the programmatic interface.
Collected 3 tasks.


────────────────────────────────────────────────────────────────────────────────────────────────────────────────
╭──────────────── Summary ─────────────────╮
│  3  Collected tasks                      │
│  3  Skipped because unchanged  (100.0%)  │
╰──────────────────────────────────────────╯
────────────────────────────────────────── Succeeded in 0.07 seconds ───────────────────────────────────────────

So, for some reason it starts two sessions. But my code only starts one and is equivalent to the example.

Problem description

Mainly, it is a display bug again, similar to #621.

Expected Output

I was expecting only one pytask session to show up.

@noppelmax noppelmax added the bug Something isn't working label Nov 15, 2024
@noppelmax noppelmax changed the title BUG: BUG: Functional Interface generates two sessions Nov 15, 2024
@tobiasraabe
Copy link
Member

Hi @noppelmax, thanks for spending the effort on reproducing the issue on the main branch as well.

Unfortunately, when I copy over the script and execute it, everything works

  1. Copy the script to script.py.
  2. uv init
  3. uv add pytask pytask-parallel
> uv run python .\script.py
──────────────────────────── Start pytask session ─────────────────────────────
Platform: win32 -- Python 3.11.7, pytask 0.5.1, pluggy 1.5.0
Root: C:\Users\tobia\git\test
Plugins: pytask_parallel-0.5.0
Collected 3 tasks.

╭────────────────────────────────────┬─────────╮
│ Task                               │ Outcome │
├────────────────────────────────────┼─────────┤
│ script.py::task_create_first_file  │ .       │
│ script.py::task_create_second_file │ .       │
│ script.py::task_merge_files        │ .       │
╰────────────────────────────────────┴─────────╯

───────────────────────────────────────────────────────────────────────────────
╭─────────── Summary ────────────╮
│  3  Collected tasks            │
│  3  Succeeded        (100.0%)  │
╰────────────────────────────────╯
────────────────────────── Succeeded in 0.09 seconds ──────────────────────────

I get a similar, not the same, output as you do, if I execute

> uv run pytask .\task_script.py
──────────────────────────── Start pytask session ─────────────────────────────
Platform: win32 -- Python 3.11.7, pytask 0.5.1, pluggy 1.5.0
Root: C:\Users\tobia\git\test
Plugins: pytask_parallel-0.5.0
──────────────────────────── Start pytask session ─────────────────────────────
Platform: win32 -- Python 3.11.7, pytask 0.5.1, pluggy 1.5.0
Root: C:\Users\tobia\git\test
Plugins: pytask_parallel-0.5.0
Exit: pytask tried to launch a second live display which is impossible. the    
issue occurs when you use pytask on the command line on a task module that uses
the programmatic interface of pytask at the same time. Use either the command 
line or the programmatic interface.
Collected 2 tasks.

╭────────────────────────────────────────┬─────────╮
│ Task                                   │ Outcome │
├────────────────────────────────────────┼─────────┤
│ task_script.py::task_create_first_file │ .       │
│ task_script.py::task_merge_files       │ .       │
╰────────────────────────────────────────┴─────────╯

───────────────────────────────────────────────────────────────────────────────
╭─────────── Summary ────────────╮
│  2  Collected tasks            │
│  2  Succeeded        (100.0%)  │
╰────────────────────────────────╯
────────────────────────── Succeeded in 0.06 seconds ──────────────────────────

Is maybe something else necessary to reproduce the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants