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

Incomplete output displayed and [Done] exited with code=null #171

Closed
sulbig opened this issue Aug 30, 2017 · 16 comments · Fixed by #428
Closed

Incomplete output displayed and [Done] exited with code=null #171

sulbig opened this issue Aug 30, 2017 · 16 comments · Fixed by #428
Labels

Comments

@sulbig
Copy link

sulbig commented Aug 30, 2017

When running a program with lots of console output, I'm getting a "[Done] exited with code=null in 0.0XX seconds" before all of the output has actually been written to the console.

Below is a simple Python3 example to reproduce the problem. Each time the code is run, the console output will enumerate to a different count value before it stops with the code=null exit code.

for count in range(100000):
    print(count)

The output window displays...

...
37345
37346
37347
37348
37349
37
[Done] exited with code=null in 0.044 seconds

If I run the same example in the Visual Studio Code terminal window, the full expected output is displayed every time.

@formulahendry
Copy link
Owner

For quick turnaround, you could use below setting (File->Preference->Settings) to run code in Integrated Terminal:

{
    "code-runner.runInTerminal": true
}

Also, you may try below setting to run:

{
    "code-runner.executorMap.python": "python -u"
}

Are those options working for you?

@yinguobing
Copy link

Same issue, and the first option works.

{
    "code-runner.runInTerminal": true
}

@sulbig
Copy link
Author

sulbig commented Aug 31, 2017

The first option suggested successfully displays every print statement in the example above in the Terminal window, every time.

// First option
{
    "code-runner.runInTerminal": true
}

The second option suggested has the original issue displayed in the Output window.

// Second option
{
    "code-runner.executorMap.python": "python -u"
}

@sulbig
Copy link
Author

sulbig commented Sep 1, 2017

I'm not a Javascript/NodeJS programmer, but I did some reading of the code in this extension, as well as the NodeJS API, and think I may have come across something interesting.

I see that the exec() fucntion of child_process is being used in the executeCommandInOutputChannel() function in the codeManager.ts file. I'm understanding that exec() spawns a shell and executes the command within that shell, buffering any generated output. There is a maxBuffer option that is documented as:

maxBuffer <number> : Largest amount of data in bytes allowed on stdout or stderr. (Default: 200*1024) If exceeded, the child process is terminated. See caveat at maxBuffer and Unicode.

https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

It looks as though the spawn() function should be used instead, since the data is streamed as standard IO objects -- not buffered strings.

@1ycx
Copy link

1ycx commented Mar 1, 2018

Also, you may try below setting to run:

{
    "code-runner.executorMap.python": "python -u"
}

Are those options working for you?

You Could Make It
"code-runner.executorMap": { "python":"clear; python3 -u" }
For Python3/3.6 With A Clear Terminal Output.

@formulahendry

Thanks Man.
BTW, What's The Actual Problem Here ?

I'm Facing A Similar Problem Where The Code Just Goes On And On . . . And Only When I Click Ctrl+Alt+M Does The Execution Stop.

[Running] python "/home/yahyaa/Desktop/a.py"  //Goes On Till The Keys Are Pressed

[Done] exited with code=null in 1.766 seconds

@DR-Watt
Copy link

DR-Watt commented Jul 26, 2018

Same problem in PHP!

First option works too...

@Khalilsqu
Copy link

Same problem python vsc windows 10

@bemanetoglu
Copy link

First option works. Thanks for the answer. 👌

@z33kz33k
Copy link

z33kz33k commented Oct 25, 2018

This issue can lead to pretty nasty problems (debugging-wise) if one decides to e.g. create some output files and print some lengthy message about it on stout in the same loop. What happens is, SILENTLY, some of the files will go missing. Consider the below Python example:

for i in range(1, 4501):
    prefix = "debug/vscodetest/"
    suffix = ".txt"
    path = "{}{}{}".format(prefix, str(i), suffix)
    with open(path, mode="w") as f:
        f.write("Hello world!")
            
    print("#{} file printed {}".format(str(i), "padding"*3))

It only takes to change padding*3 to padding*4 to have couple hundred files gone missing. Have a good time noticing it, let alone trying to figure out what happened (especially considering these rather aren't gonna be some helloworlds in a simple range() loop).

In my case I first thought it was some strange problem with Python (performance issue, stout redirection I used not working properly etc.), then that it probably is some strange problem with VS Code and at last after one day at work spent on this I finally landed here.

I think the problem at least merits some more visibility (maybe its own separate issue?)

@NBelal
Copy link

NBelal commented Nov 30, 2018

The same have happened to me, but in my case after applying your suggestions (specially the one of running Python script in the Terminal), I can see the starting point of the output

@oleghwang
Copy link

oleghwang commented Mar 6, 2019

Hello, can anybody help me please. When i'm running terminal, i 've got very long details in terminal. How can i remove it, just to have the result of code
thank you in advance
terminal3

wanna have like this one
terminal2

@nuptownboy
Copy link

Did Oleg Hwang get an answer to this question as I have same question exactly and can only find the question and no answer?

@sauravexodus
Copy link

If you run the code in the terminal then it works. Usually, it is a buffer issue and your terminal will have a larger buffer.

@homerjed
Copy link

homerjed commented Jun 7, 2019

First option works

For quick turnaround, you could use below setting (File->Preference->Settings) to run code in Integrated Terminal:

{
    "code-runner.runInTerminal": true
}

Also, you may try below setting to run:

{
    "code-runner.executorMap.python": "python -u"
}

Are those options working for you?

Works for VS code running python; note further that the output window was not printing in a 'co-moving' fashion so I couldn't see the output as it went along. Thanks.

@JeffreyCA
Copy link
Contributor

@formulahendry could you take a look at #428?

formulahendry pushed a commit that referenced this issue Aug 14, 2019
* Use spawn instead of exec to execute command

* Use toString instead of TextDecoder
@formulahendry
Copy link
Owner

Fixed in v0.9.13. Thanks @JeffreyCA !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.