cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How do i stop pyspark from outputting text

halox6000
New Contributor III

I am using a tqdm progress bar to monitor the amount of data records I have collected via API. I am temporarily writing them to a file in the DBFS, then uploading to a Spark DataFrame. Each time I write to a file, I get a message like 'Wrote 8873925 bytes.' How do I stop it from outputting this?

1 REPLY 1

MathieuDB
Databricks Employee
Databricks Employee

Hello @halox6000,

You could temporarily redirect console output to a null device for these write operations.

Try this out:

@contextlib.contextmanager
def silence_dbutils():
    with contextlib.redirect_stdout(io.StringIO()):
        yield

# Usage in your code
with silence_dbutils():
    dbutils.fs.put("/path/to/your/file.txt", "Your content here", True)

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now