Skip to content

Commit b092f48

Browse files
committed
add stdour and stderr for py files
1 parent 939a2aa commit b092f48

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

jupyter_scheduler/environments.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ def manage_environments_command(self) -> str:
6666
return ""
6767

6868
def output_formats_mapping(self) -> Dict[str, str]:
69-
return {"ipynb": "Notebook", "html": "HTML"}
69+
return {
70+
"ipynb": "Notebook",
71+
"html": "HTML",
72+
"stdout": "Output",
73+
"stderr": "Errors",
74+
}
7075

7176

7277
class StaticEnvironmentManager(EnvironmentManager):
@@ -90,7 +95,12 @@ def manage_environments_command(self) -> str:
9095
return ""
9196

9297
def output_formats_mapping(self) -> Dict[str, str]:
93-
return {"ipynb": "Notebook", "html": "HTML"}
98+
return {
99+
"ipynb": "Notebook",
100+
"html": "HTML",
101+
"stdout": "Output",
102+
"stderr": "Errors",
103+
}
94104

95105

96106
class EnvironmentRetrievalError(Exception):

jupyter_scheduler/handlers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ async def post(self):
308308
# Ensure backend ID is stored with the job
309309
payload["backend"] = backend.config.id
310310
scheduler = backend.scheduler
311+
312+
# Set default output_formats for Python backend
313+
if backend.config.id == "jupyter_server_py" and not payload.get("output_formats"):
314+
payload["output_formats"] = ["stdout", "stderr"]
311315
else:
312316
# Fallback to default scheduler (backwards compatibility)
313317
scheduler = self.scheduler

jupyter_scheduler/python_executor.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,15 @@ def execute(self):
3333
env=env,
3434
)
3535

36-
# Capture side effect files (same pattern as DefaultExecutionManager)
37-
self.add_side_effects_files(staging_dir)
38-
39-
# Write stdout/stderr to staging directory
40-
stdout_path = os.path.join(staging_dir, "stdout.log")
41-
stderr_path = os.path.join(staging_dir, "stderr.log")
42-
43-
with fsspec.open(stdout_path, "w", encoding="utf-8") as f:
36+
# Write stdout/stderr to staging_paths (keys match output_formats)
37+
with fsspec.open(self.staging_paths["stdout"], "w", encoding="utf-8") as f:
4438
f.write(result.stdout)
45-
with fsspec.open(stderr_path, "w", encoding="utf-8") as f:
39+
with fsspec.open(self.staging_paths["stderr"], "w", encoding="utf-8") as f:
4640
f.write(result.stderr)
4741

42+
# Capture any additional side effect files AFTER writing stdout/stderr
43+
self.add_side_effects_files(staging_dir)
44+
4845
if result.returncode != 0:
4946
raise RuntimeError(
5047
f"Script exited with code {result.returncode}\nstderr: {result.stderr[:500]}"

0 commit comments

Comments
 (0)