roipoussiere / cadquery-vscode

Build parametric 2D/3D CAD models in VSCode with the CadQuery library.
https://open-vsx.org/extension/roipoussiere/cadquery
MIT License
18 stars 4 forks source link

Move imports to show #3

Closed bernhard-42 closed 2 years ago

bernhard-42 commented 2 years ago

The next Jupyter-Cadquery will come with multiprocessing support for large assemblies. This doesn't work well with flask. I made it run by forcing imports (initializing multiprocessng) being done after start of flask:

import cadquery

from flask import Flask, request

app = Flask(__name__)
json_result = "[{}, {}]"

def show(model):
    global json_result

    from jupyter_cadquery.utils import numpy_to_json
    from jupyter_cadquery.cad_objects import to_assembly
    from jupyter_cadquery.base import _tessellate_group

    json_result = numpy_to_json(_tessellate_group(to_assembly(model)))

@app.route("/", methods=["GET", "POST"])
def root():
    if request.method == "GET":
        return "Please send a CadQuery Python script in a POST request.\n"
    elif request.method == "POST":
        exec(request.get_data().decode())
        return json_result

def run():
    app.run(host="0.0.0.0", port=4999, debug=False)

Is this something you could change?

roipoussiere commented 2 years ago

I released version 0.1.2 of cadquery-server that includes this change, could you give a try?

bernhard-42 commented 2 years ago

works fine for me, thx