小编the*_*can的帖子

Docker bash shell 脚本无法捕获 SIGINT 或 SIGTERM

我的目录中有以下两个文件:

Dockerfile

FROM debian

WORKDIR /app
COPY start.sh /app/

CMD ["/app/start.sh"]
Run Code Online (Sandbox Code Playgroud)

start.sh(使用权限 755 chmod +x start.sh

FROM debian

WORKDIR /app
COPY start.sh /app/

CMD ["/app/start.sh"]
Run Code Online (Sandbox Code Playgroud)

然后我运行以下命令:

$ docker build . -t tmp
$ docker run --name tmp tmp
Run Code Online (Sandbox Code Playgroud)

然后我期望按 Ctrl+C 会向程序发送 SIGINT,该程序会将 SIGINT 打印到屏幕然后退出,但这并没有发生。

我还尝试运行$ docker stop tmp,我希望它会向程序发送一个 SIGTERM ,但$ docker logs tmp之后检查显示 SIGTERM 未被捕获。

为什么 bash 脚本没有捕获 SIGINT 和 SIGTERM?

bash shell sigint sigterm docker

15
推荐指数
2
解决办法
1万
查看次数

python 3curses 包装器的类型提示

对于Python 3中的curses编程,使用curses.wrapper函数来封装curses程序、处理错误和设置是很有用的。

import curses

def main(stdscr):
    # Curses program here
    pass

curses.wrapper(main)
Run Code Online (Sandbox Code Playgroud)

但是如何向对象添加类型提示stdscr呢?添加类型提示将允许 IDE 为对象提供更好的智能感知stdscr并显示可用的方法和属性。(顺便说一句,我正在使用 Visual Studio Code)

下面的代码:

import curses

def main(stdscr):
    s = str(type(stdscr))
    stdscr.clear()
    stdscr.addstr(0,0,s)
    stdscr.refresh()
    stdscr.getkey()

curses.wrapper(main)
Run Code Online (Sandbox Code Playgroud)

...表明那type(stdscr)<class '_curses.window'>

但这不起作用:

import curses
import _curses

# This does not work:
def main(stdscr: _curses.window):
    # No intellisense provided for stdscr
    pass

curses.wrapper(main)
Run Code Online (Sandbox Code Playgroud)

我不太确定还可以尝试什么。

python curses type-hinting visual-studio-code

3
推荐指数
1
解决办法
755
查看次数