microsoft / azuredatastudio

Azure Data Studio is a data management and development tool with connectivity to popular cloud and on-premises databases. Azure Data Studio supports Windows, macOS, and Linux, with immediate capability to connect to Azure SQL and SQL Server. Browse the extension library for more database support options including MySQL, PostgreSQL, and MongoDB.
https://learn.microsoft.com/sql/azure-data-studio
MIT License
7.54k stars 898 forks source link

PowerShell notebook cells hang and run forever if you change the prompt #14065

Open codykonior opened 3 years ago

codykonior commented 3 years ago

Issue Type: Bug

PowerShell notebooks hang if you redefine your PowerShell prompt. It's not uncommon for enterprise PowerShell modules to override the prompt with more a more useful one on load.

To Reproduce

Create a PowerShell notebook with 3 code cells:

Write-Host "I run okay"
Write-Host "Me too"
Write-Host "Die!"
function Prompt { "ABC> "}

You can run the first two however you want. Once you run the third one it will never end and kill the notebook. Stopping the cell doesn't work, and running the previous cells no longer works. You can't act normally again until you restart ADS.

Other variations of setting the prompt such as with Set-Alias also break the notebook.

Workarounds

  1. Notebooks seem to set the prompt to an empty function {} on startup. So if you can revert the prompt like this at the end of every cell then you won't have the problem. e.g.
if (Test-Path Alias:Prompt) { Remove-Item Alias:Prompt }
function Prompt {}

But this means every cell needs nonsensical fixup code at the end.

  1. In your PowerShell modules that improve the prompt, wrap it in a check that skips it if the prompt is empty.

Azure Data Studio version: azuredatastudio 1.25.2 (4d4917d328ab7a7526817a0f0ef03237a79aa54d, 2021-01-20T22:52:13.492Z) OS version: Windows_NT x64 10.0.17763

Extensions: none

VasuBhog commented 2 years ago

This is due to how the Powershell_kernel is set up. I would recommend using the .Net Interactive PowerShell Kernel instead as that has more consistent reliability.

Install guide for .Net Kernels - https://github.com/dotnet/interactive/blob/main/docs/NotebookswithJupyter.md

Once installed you can enable the setting in ADS for showing all kernels and then change the kernels to .Net Powershell.