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: 

Debugging python code outside of Notebooks

vvzadvor
New Contributor III

Hi experts,

Does anyone know if there's a way of properly debugging python code outside of notebooks?

We have a complicated python-based framework for loading files, transforming them according to the business specification and saving the results into delta tables. The whole framework is structured as a python project with multiple folders, .py files and classes inside of these files. In order to perform a proper debugging (with breakpoints, conditional breakpoints, stepping into methods and so on) I had to set up a local development environment on my Windows machine that mimics our cloud setup (local directories serving as Azure storage containers, delta tables created locally and so on).

This setup works, but it's not really convenient. I was wondering if there's a way of performing advanced debugging in Databricks either remotely from my IDE (VSCode) or via Databricks UI?

After searching the forum I found no definitive answer to this question. Notebook debugger is not an option because it's meant for notebooks only. %debug command and pdb are inconsistent in terms of their behavior. Databricks Connect is something I can't test at work because of our security setup (too restrictive).

Best regards,
Vladislavs

1 ACCEPTED SOLUTION

Accepted Solutions

szymon_dybczak
Contributor III

Other than databricks connect, I'm afraid there isn't much option there. 

You can also try to setup your own apache spark environment with docker, but any commands specific to datbricks will not work. 

 

View solution in original post

4 REPLIES 4

szymon_dybczak
Contributor III

Other than databricks connect, I'm afraid there isn't much option there. 

You can also try to setup your own apache spark environment with docker, but any commands specific to datbricks will not work. 

 

vvzadvor
New Contributor III

Thank you for the response. Have you tried remote debugging with Databricks Connect V2? I am particularly interested in stepping into the methods from the libraries installed on the cluster. Is it possible?

As for setting up a local Spark environment with Docker - it is even more complicated in my company due to security restrictions. The setup I mentioned in my post was the best thing I could achieve given the limitations.

vvzadvor
New Contributor III

I actually managed to get a permission for using pat token to connect to databricks development environment. And with that I managed to set up VSCode extension for databricks, connect to cluster and create sync location. I can even run spark apps from my local machine on a databricks cluster. However, whenever I am trying to debug the code, debugger simply skips the breakpoints.

vvzadvor
New Contributor III

OK, I can now confirm that remote debugging with stepping into your own libraries installed on the cluster is possible and is actually pretty convenient using a combination of databricks-connect Python library and a Databricks extension for VSCode. Setting it up is pretty straight forward as well (everything is documented). Only one part confused me: all your Python code runs locally and only spark code is sent to the cluster. It means that your launch.json might end up looking like this (see below) and you actually need to use a profile related to debugpy (with justMyCode set to false) when initiating debugging session. Hopefully, it helps someone.

vvzadvor_0-1721374291467.png

 



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