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

suppress_stdout_stderr seems to suppress to much #31

Closed
dcowden opened this issue Dec 6, 2018 · 7 comments
Closed

suppress_stdout_stderr seems to suppress to much #31

dcowden opened this issue Dec 6, 2018 · 7 comments
Labels
bug Something isn't working

Comments

@dcowden
Copy link
Member

dcowden commented Dec 6, 2018

Issue by gntech
Wednesday May 16, 2018 at 17:40 GMT
Originally opened as dcowden/cadquery#267


When exporting a STEP-file cadquery swallows some of the things written to stdout.

Consider the following script. Run from terminal with python.

import cadquery as cq

print("before creating model")

m = cq.Workplane("XY").box(10, 10, 10)

print("after creating model and before exporting model")

with open("testfile.step", "w") as f:
    cq.exporters.exportShape(m, "STEP", f)

print("after exporting model")

I would expect to get to get 3 print statements but I only get the last one after exporting model

I suspect that this has something to with the function suppress_stdout_stderr that is designed to suppress some messages from freecad regarding the step-export.

If I run the script like so instead I get all 3 print statments but also some messages from freecad regarding step creation. Using this form of the export I bypass the suppress_stdout_stderr()

import cadquery as cq

print("before creating model")

m = cq.Workplane("XY").box(10, 10, 10)

print("after creating model and before exporting model")

m.val().exportStep("out.step")

print("after exporting model")

My suggestion for how to fix this issue is to contact freecad upstream to see if we can get a clean step output from freecad to get rid of suppress_stdout_stderr. Because, seriously, the suppress_stdout_stderr() is not the ideal solution. :)

@dcowden dcowden added the bug Something isn't working label Dec 6, 2018
@dcowden
Copy link
Member Author

dcowden commented Dec 6, 2018

Comment by fragmuffin
Thursday May 17, 2018 at 06:43 GMT


It seems strange that you're missing messages before you run the exporter.
Is this because print buffers output for a short while before flushing them?
Could the fix involve flushing the buffer print uses?

My suggestion for how to fix this issue is to contact freecad upstream [...] because, seriously, the suppress_stdout_stderr() is not the ideal solution. :)

totally agree 👍. Those wacky FreeCAD people!

@dcowden
Copy link
Member Author

dcowden commented Dec 6, 2018

Comment by gntech
Thursday May 17, 2018 at 07:13 GMT


It seems strange that you're missing messages before you run the exporter.
Is this because print buffers output for a short while before flushing them?

Yes, this is what I think as well. It is bad since I want to use the print statements to show progress of the script. And the buffering makes all the print come at the very end of the script run, so much for progress. :)

@dcowden
Copy link
Member Author

dcowden commented Dec 6, 2018

Comment by gntech
Thursday May 17, 2018 at 11:08 GMT


I found a possible solution to the problem that freecad buffers everything that is written to stdout until the end of execution.

sys.stdout.flush()

See https://forum.freecadweb.org/viewtopic.php?f=22&t=28354&hilit=Step+stdout

@dcowden
Copy link
Member Author

dcowden commented Dec 6, 2018

Comment by dcowden
Thursday May 17, 2018 at 11:21 GMT


...or we could just accelerate progress to pull in @adam-urbanczyk 's OCC branch and convert this function to use OCC directly and just skip freecad. that'd be my vote.

Last I checked his branch had just about everything working without FreeCAD.

I think we should start pulling in his branch, and then start slowly converting CQ functions to use OCC directly, initially, using the OCC bundled with FreeCAD.

@dcowden
Copy link
Member Author

dcowden commented Dec 6, 2018

Comment by fragmuffin
Thursday May 17, 2018 at 11:54 GMT


@gntech sys.stdout.flush() worked for me!
Adding it to the start of suppress_stdout_stderr.__enter__ should do the trick.

@adam-urbanczyk @dcowden

[adam-urbanczyk 's] branch had just about everything working without FreeCAD

That's exciting! @adam-urbanczyk is it time to start migrating cqparts' freecad dependencies out?

@dcowden
Copy link
Member Author

dcowden commented Dec 6, 2018

Comment by dcowden
Thursday May 17, 2018 at 12:04 GMT


@adam-urbanczyk @fragmuffin it is definitely close enough i think its time to try to make it happen. I think he reported having all of the tests passing at the time even. Our test coverage is pretty good, so I think that means we're pretty close.

I've created #268 to get the ball rolling on that.

@jmwright jmwright changed the title suppress_stdout_stderr seams to suppress to much suppress_stdout_stderr seems to suppress to much Feb 5, 2021
@jmwright
Copy link
Member

jmwright commented Feb 5, 2021

This is a FreeCAD issue, so I'm closing it. I put an issue on the FreeCAD workbench repo since it is the only place the old CadQuery 1.x library is still being maintained, although at a very minimal level.

@jmwright jmwright closed this as completed Feb 5, 2021
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