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

PDL output corrupt in Jupyter notebook #602

Open
esnible opened this issue Feb 28, 2025 · 2 comments
Open

PDL output corrupt in Jupyter notebook #602

esnible opened this issue Feb 28, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@esnible
Copy link
Member

esnible commented Feb 28, 2025

Describe the bug
PDL's output can be corrupt in the Jupyter notebook

To Reproduce
Open our example examples/notebooks/pdl.ipynb and run the very first example.

The output is some variation of

What is the meaning of life?
The meaning of life is a philosophical and metaphysical question related to the purpose or significance of life or existence in general. This question has been asked for centuries and doesn't have a definitive answer as it can vary greatly depending on one's personal beliefs, cultural background, religious faith, or philosophical perspective.

Some people find meaning through personal growth, relationships, love, or through contributing to the betterment of humanity. Others may find it through spirituality or religious beliefs, seeing life as a test or a journey towards a higher purpose. 

 life has no inherent meaning, and it's up to each individual to create their own purpose. On the other hand, some philosophical and religious traditions propose that the meaning of life is to seek God, attain enlightenment, or achieve harmony with the universe.

 life is a deeply personal and subjective concept. It's something that each person might need to explore and discover for themselves.

Expected behavior
The third and fourth paragraphs are missing some text. The last paragraph should be

In essence, the meaning of life is a deeply personal and subjective concept. It's something that each person might need to explore and discover for themselves.

Additional notes
To reproduce, test using a version of PDL with #601 merged because earlier versions did not default the temperature to 0.

I am testing with JupyterLab Version 4.3.4.

@esnible esnible added the bug Something isn't working label Feb 28, 2025
@esnible
Copy link
Member Author

esnible commented Mar 3, 2025

The problem seems to be a Jupyter bug. If instead of using PDL I replace our cell magic with

    def pdl(self, line, cell, local_ns):
        print("\x1b[32mThe meaning of life is a philosophical and metaphysical question.\n\nSome people \x1b[0m", end="", flush=True)
        print("More text.")
        return

I get corrupted output. (Removing the flush=True fixes the problem.)

Image

@esnible
Copy link
Member Author

esnible commented Mar 3, 2025

Created jupyterlab/jupyterlab#17358 to track. The problem is not related to coloring or the extension. It seems to be a general problem with flush=True and newlines in Jupyter.

However, although setting flush=False seems to improve the output, the output is still broken for me in Jupyter. It is not the coloring that is the problem. Investigating.

@esnible esnible self-assigned this Mar 3, 2025
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

1 participant