[Python] Polars: What is the way to limit number of threads? [duplicate]

Discussão em 'Python' iniciado por Stack, Novembro 22, 2025.

  1. Stack

    Stack Membro Participativo

    Polars is consuming all the threads apparently in my app deployed using gunicorn+supervisor. What is the best way to limit the number of threads for polars? I am not reading a csv or writing a csv (using in below code for example only)? also, any way to log the number of threads being consumed by polars at any time?.

    ├── polars_script.py

    import polars as pl

    df = pl.read_csv("input.csv")

    # Perform some basic operations
    df = df.filter(pl.col("column_name") > 50) # Filter rows where 'column_name' > 50
    df = df.with_column((pl.col("column_name") * 2).alias("new_column")) # Add a new column

    # Write the DataFrame to a new CSV file
    df.write_csv("output.csv")

    print("Data processing complete. Output saved to output.csv")


    ├── app.py

    from flask import Flask
    import polars as pl

    app = Flask(__name__)

    @app.route('/process')
    def process_data():
    # Read a CSV file into a Polars DataFrame
    df = pl.read_csv("input.csv")

    # Perform some basic operations
    df = df.filter(pl.col("column_name") > 50) # Filter rows where 'column_name' > 50
    df = df.with_column((pl.col("column_name") * 2).alias("new_column")) # Add a new column

    # Write the DataFrame to a new CSV file
    df.write_csv("output.csv")

    return "Data processing complete. Output saved to output.csv"

    if __name__ == "__main__":
    app.run()


    ├── gunicorn_config.py

    bind = "0.0.0.0:8000"
    workers = 20



    gunicorn -c gunicorn_config.py app:app

    Continue reading...

Compartilhe esta Página