mpdallexit.py
来自「刚才是说明 现在是安装程序在 LINUX环境下进行编程的MPICH安装文件」· Python 代码 · 共 43 行
PY
43 行
#!/usr/bin/env python## NOTE: we do NOT allow this pgm to run via mpdrootfrom os import environfrom sys import argv, exitfrom socket import socket, AF_UNIX, SOCK_STREAMfrom signal import signal, SIG_DFL, SIGINT, SIGTSTP, SIGCONTfrom mpdlib import mpd_set_my_id, mpd_send_one_msg, mpd_recv_one_msg, \ mpd_get_my_username, mpd_raise, mpdErrordef mpdallexit(): mpd_set_my_id('mpdallexit_') if len(argv) > 1 and ( argv[1] == '-h' or argv[1] == '--help') : print 'usage: mpdallexit (no args)' print 'causes all mpds in the ring to exit' exit(-1) consoleName = '/tmp/mpd2.console_' + mpd_get_my_username() conSocket = socket(AF_UNIX, SOCK_STREAM) # note: UNIX socket try: conSocket.connect(consoleName) except Exception, errmsg: print 'cannot connect to local mpd at %s' % consoleName exit(-1) mpd_send_one_msg(conSocket, {'cmd':'mpdallexit'}) msg = mpd_recv_one_msg(conSocket) if not msg or msg['cmd'] != 'mpdallexit_ack': if msg['cmd'] == 'already_have_a_console': mpd_raise('mpd already has a console (e.g. for long ringtest); try later') else: mpd_raise('unexpected message from mpd: %s' % (msg) ) conSocket.close()def sigint_handler(signum,frame): exit(-1)if __name__ == '__main__': signal(SIGINT,sigint_handler) try: mpdallexit() except mpdError, errmsg: print 'mpdallexit failed: %s' % (errmsg)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?