Python:zmq.error.zmq错误:地址已在美国

2024-03-28 11:42:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个“Hello world”服务器:

import time
import zmq
import mutagen
import json

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:64108")

try:

    while True:
        #  Wait for next request from client
        message = socket.recv()
        jsn = message.decode('utf8')
        rq = json.loads(jsn)

        reply = 'Idle'

        if rq['request'] == 'settags':
            audio = mutagen.File(rq['file'], easy=True)
            if audio:
                reply = "track number set to [{}]".format(rq['tags']['tracknumber'])  # Debug info
                for tag, value in rq['tags'].items():
                    audio[tag] = value
                audio.save()
        #  Send reply back to client
        socket.send_string(reply)

except keyboardInterrupt as e:
    sys.exit(e)

除了第一次尝试外,任何尝试都会以这样的方式结束,这很自然:

^{pr2}$

我只想检查地址,终止中止的脚本,并去掉堆栈跟踪。不知怎么的,我没能找到一个有用的答案。我该怎么办?在


Tags: importclientjsontruemessageforrequestcontext