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

ccall()-ed function output not shown until execution is finished #153

Closed
cbecker opened this issue Mar 1, 2014 · 6 comments
Closed

ccall()-ed function output not shown until execution is finished #153

cbecker opened this issue Mar 1, 2014 · 6 comments
Labels

Comments

@cbecker
Copy link

cbecker commented Mar 1, 2014

I am not sure how to enable logging of stdout for ccall()-ed libraries. For example, lets make ``test.c` be

#include <stdio.h>

void test()
{   int i=0;
    for (i=0; i < 10; i++)
    {
        printf("hehe\r\n");
        fflush(stdout);
        system("sleep 0.5");
    }
}

compite with gcc -shared test.c -o test.so -fPIC, and then call it from IJulia (console or qtconsole):

ccall( (:test, "./test.so"), None, () )

Instead of seeing a series of 'hehe', separated by a 500ms pause, I see nothing at all with console, while I see the whole bunch of stdout appearing instantly once the ccall returns with qtconsole. It looks like something related to how stdout is handled, maybe close to #23

Thanks.

@stevengj
Copy link
Member

stevengj commented Mar 1, 2014

While your C code is running, the IJulia kernel is not running; there is no way for it to send stdout to the front-end until you give IJulia some cycles.

I don't see any way to fix this, short of having your C code call the the equivalent of yield() occasionally in the julia jl_* API.

@cbecker
Copy link
Author

cbecker commented Mar 1, 2014

Thanks Steven. That is an option in my case, because I generally link to libjulia.so, so that would help. It gets trickier with other libraries of course.

@stevengj
Copy link
Member

stevengj commented Mar 1, 2014

It would be nice to have a jl_yield() function in the Julia API to make this sort of thing easier. Maybe file an issue in Julia.

@cbecker
Copy link
Author

cbecker commented Mar 1, 2014

Yes, would be great. The issue is that yield() is in julia code now, and doing jl_eval_string("yield()"); crashes Julia when the function returns.

About my original question, I understand if the contents I printed appear when the function returns, but in the case of using ipython console --profile julia I don't get any of the output at all.

@stevengj
Copy link
Member

stevengj commented Mar 1, 2014

@minrk, does the ipython console not support stream messages?

@minrk
Copy link
Contributor

minrk commented Mar 3, 2014

It does - all Python print statements are stream messages. I can print with println("1") in ipython console --profile julia.

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

No branches or pull requests

3 participants