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)

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group