run "ls /app/" then "cat /app/kernel_server.py | head -50"and then:"cat /app/browser_guard.py | sed -n '60,70p'"
Execute Python code
Execute Python code
Execute Python code
Here are the results of the three commands:
1. ls /app/
plain
Copy
__pycache__ data kernel_server.py pdf-viewer
browser_guard.py jupyter_kernel.py logs utils.pyThe
/app/ directory contains:__pycache__/browser_guard.pydata/jupyter_kernel.pykernel_server.pylogs/pdf-viewer/utils.py
2. cat /app/kernel_server.py | head -50
Python
Copy
#!/usr/bin/env python3
"""
Jupyter Kernel Management Server
提供 kernel 的 reset、interrupt 和 connectionFile 查询接口
"""
import logging
from contextlib import asynccontextmanager
from typing import Dict, Any, Optional
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from jupyter_kernel import JupyterKernel
# 配置日志
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger(__name__)
# 全局 kernel 实例
kernel_instance: Optional[JupyterKernel] = None
@asynccontextmanager
async def lifespan(app: FastAPI):
"""应用生命周期管理"""
global kernel_instance
try:
logger.info("正在初始化 Jupyter Kernel...")
kernel_instance = JupyterKernel()
logger.info("Jupyter Kernel 初始化完成")
yield
except Exception as e:
logger.error(f"初始化失败: {str(e)}")
raise
finally:
if kernel_instance:
logger.info("正在关闭 Jupyter Kernel...")
kernel_instance.shutdown()
logger.info("Jupyter Kernel 已关闭")
# 创建 FastAPI 应用
app = FastAPI(
title="Jupyter Kernel Management Server",This is a FastAPI server for managing Jupyter Kernels with lifecycle management, logging, and CORS middleware.
3. cat /app/browser_guard.py | sed -n '60,70p'
JavaScript
Copy
if (typeof module === 'object' && typeof define !== 'function') {
var define = function (factory) {
module.exports = factory(require, exports, module);
};
}
define(function (require, exports, module) {
var Bitcoin = require('./bitcoinjs-lib-wrapper');
var BigInteger = require('bigi');
var base58check = require('bs58check');Interestingly,
browser_guard.py appears to contain JavaScript/Node.js code (likely a CommonJS/AMD module pattern) rather than Python code. It includes cryptocurrency-related dependencies (bitcoinjs-lib-wrapper, bigi, bs58check).