You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS EC2用nohup运行Jupyter Notebook:进程状态与输出查询

Hey there, let's tackle your two questions about running Jupyter Notebook with nohup, especially on AWS EC2:

问题1:远程服务器用nohup运行Jupyter Notebook,关闭浏览器后输出是否仍存在?

Absolutely yes! The whole point of using nohup is to keep your process running even after you disconnect from the terminal (or close your browser, which doesn't directly affect the server-side process anyway).

By default, nohup redirects all output (including Jupyter's logs and any print() statements from your scripts) to a file named nohup.out in the directory where you ran the command. Even if you close your browser, the Jupyter kernel keeps chugging along, and all those outputs will keep getting written to nohup.out until the process finishes. You can check this file anytime with commands like cat nohup.out or tail -f nohup.out to see real-time updates.

问题2:AWS EC2上用nohup启动Jupyter,关闭浏览器重开后kernel已连接但print输出停止,如何查看运行进度、确认程序状态及变量值?

I feel your pain—this is a known quirk with Jupyter where disconnected browser sessions can stop showing new print() outputs even if the kernel is still running. Here are a few practical ways to get the info you need:

  • Check the nohup.out file directly: Since all server-side output goes here, run tail -f nohup.out in your EC2 terminal. This will show you the latest print() statements and Jupyter logs in real time, so you can confirm if the program is still running and generating output. If you see new lines popping up, the process is alive and kicking.

  • Add custom log file output in your script: To make tracking easier (and avoid mixing Jupyter logs with your script's output), modify your Python code to write progress updates to a dedicated log file. For example:

    # Option 1: Redirect print to a file
    import sys
    # Save original stdout if you need it later
    original_stdout = sys.stdout
    # Write print statements to run_log.txt
    sys.stdout = open('run_log.txt', 'a')
    
    print("Processing batch 1/10...")
    # Do some work
    print("Batch 1 completed!")
    
    # Option 2: Use the logging module (more flexible)
    import logging
    logging.basicConfig(
        filename='app_progress.log',
        level=logging.INFO,
        format='%(asctime)s - %(message)s'
    )
    logging.info("Starting data processing...")
    # Your code here
    logging.info("Data processing 50% complete")
    

    Then you can run tail -f run_log.txt in the terminal to watch progress updates without relying on the browser.

  • Verify the process is still running: In your EC2 terminal, run ps aux | grep jupyter to check if the Jupyter server process is active. You can also run ps aux | grep python to find the specific kernel process running your script. If the process IDs (PIDs) show up, your program is still running.

  • Check variable values in Jupyter: Since the kernel is still connected, you can simply create a new cell in your notebook and type the name of the variable holding your results (e.g., my_result) then run the cell. This will show you the current state of the variable—even if the program is still running, you might see partial results if the variable is being updated incrementally.


内容的提问来源于stack exchange,提问作者eternity1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:14:34