MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / clearPythonNamespace

Function clearPythonNamespace

frontend/src/lib/python/executor.ts:237–262  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

235 * Clear Python namespace (keep imports)
236 */
237export async function clearPythonNamespace(): Promise<void> {
238 const pyodide = getPyodide();
239 if (!pyodide) {
240 return;
241 }
242
243 await pyodide.runPython(`
244 # Get list of user-defined variables
245 user_vars = [name for name in globals().keys()
246 if not name.startswith('_')
247 and name not in ['In', 'Out', 'exit', 'quit', 'get_plot_base64', 'df_to_dict']
248 and not callable(globals()[name])
249 and name not in ['np', 'pd', 'plt', 'matplotlib', 'numpy', 'pandas']]
250
251 # Delete user variables
252 for var in user_vars:
253 try:
254 del globals()[var]
255 except:
256 pass
257
258 # Clear matplotlib figures
259 import matplotlib.pyplot as plt
260 plt.close('all')
261 `);
262}
263
264/**
265 * Format DataFrame for display

Callers 2

pythonStore.tsFile · 0.90
handleClearNamespaceFunction · 0.85

Calls 1

getPyodideFunction · 0.90

Tested by

no test coverage detected