Netmq在收到发布后崩溃

时间:2017-01-21 16:04:22

标签: python pyzmq netmq

我们正在做一个ZMQ PUB / SUB方法。 PUB / SUB交换用dot net(.Net)编写,.Net交换的发布者用Python编写。 当Python PUB与.Net交换时,它经常崩溃,出现以下错误:

mono phoenix.exe XChange                                                                    

[73/73]Phoenix v.1.1.16.32 {DEBUG}
Command:XCHANGE 
Starting XChange: PhoenixExchange[XSubAddr:tcp://*:5201[In] XPubAddr:tcp://*:5202[In]]

Unhandled Exception:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: count
  at System.Net.Sockets.SocketAsyncEventArgs.SetBufferInternal (System.Byte[] buffer, Int32 offset, Int32 count) <0x7423bc20 + 0x000e4> in <filename unkn
own>:0 
  at System.Net.Sockets.SocketAsyncEventArgs.SetBuffer (Int32 offset, Int32 count) <0x7423d278 + 0x00027> in <filename unknown>:0 
  at AsyncIO.DotNet.NativeSocket.Receive (System.Byte[] buffer, Int32 offset, Int32 count, SocketFlags flags) <0x7423c8b0 + 0x000f3> in <filename unknown
>:0 
  at NetMQ.Core.Transports.StreamEngine.BeginRead (NetMQ.Core.Transports.ByteArraySegment data, Int32 size) <0x7423c7d0 + 0x00057> in <filename unknown>:
0 
  at NetMQ.Core.Transports.StreamEngine.HandleHandshake (Action action, SocketError socketError, Int32 bytesTransferred) <0x742399b0 + 0x007df> in <filen
ame unknown>:0 
  at NetMQ.Core.Transports.StreamEngine.Handle (Action action, SocketError socketError, Int32 bytesTransferred) <0x74238b78 + 0x0019b> in <filename unkno
wn>:0 
  at NetMQ.Core.Transports.StreamEngine.FeedAction (Action action, SocketError socketError, Int32 bytesTransferred) <0x742387c8 + 0x0002b> in <filename u
nknown>:0 
  at NetMQ.Core.Transports.StreamEngine.InCompleted (SocketError socketError, Int32 bytesTransferred) <0x7423d188 + 0x00027> in <filename unknown>:0 
  at NetMQ.Core.IOObject.InCompleted (SocketError socketError, Int32 bytesTransferred) <0x74236408 + 0x0003b> in <filename unknown>:0 
  at NetMQ.Core.Utils.Proactor.Loop () <0x74218f88 + 0x00343> in <filename unknown>:0 
  at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) <0x748a8100 + 0x000c7> in <filename unknown>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System
.Object state, Boolean preserveSyncCtx) <0x748a67bc + 0x001af> in <filename unknown>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object 
state, Boolean preserveSyncCtx) <0x748a6788 + 0x0002b> in <filename unknown>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object 
state) <0x748a66e4 + 0x0005b> in <filename unknown>:0 
  at System.Threading.ThreadHelper.ThreadStart () <0x748a82d0 + 0x00037> in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: count
  at System.Net.Sockets.SocketAsyncEventArgs.SetBufferInternal (System.Byte[] buffer, Int32 offset, Int32 count) <0x7423bc20 + 0x000e4> in <filename unkn
own>:0 
  at System.Net.Sockets.SocketAsyncEventArgs.SetBuffer (Int32 offset, Int32 count) <0x7423d278 + 0x00027> in <filename unknown>:0 
  at AsyncIO.DotNet.NativeSocket.Receive (System.Byte[] buffer, Int32 offset, Int32 count, SocketFlags flags) <0x7423c8b0 + 0x000f3> in <filename unknown
>:0 
  at NetMQ.Core.Transports.StreamEngine.BeginRead (NetMQ.Core.Transports.ByteArraySegment data, Int32 size) <0x7423c7d0 + 0x00057> in <filename unknown>:
0 
  at NetMQ.Core.Transports.StreamEngine.HandleHandshake (Action action, SocketError socketError, Int32 bytesTransferred) <0x742399b0 + 0x007df> in <filen
ame unknown>:0 
  at NetMQ.Core.Transports.StreamEngine.Handle (Action action, SocketError socketError, Int32 bytesTransferred) <0x74238b78 + 0x0019b> in <filename unkno
wn>:0 
  at NetMQ.Core.Transports.StreamEngine.FeedAction (Action action, SocketError socketError, Int32 bytesTransferred) <0x742387c8 + 0x0002b> in <filename u
nknown>:0 
  at NetMQ.Core.Transports.StreamEngine.InCompleted (SocketError socketError, Int32 bytesTransferred) <0x7423d188 + 0x00027> in <filename unknown>:0 

python代码是一个简单的pub。

import sys, os
is_py2 = sys.version[0] == '2'

import time, datetime
import zmq 
from xml.etree import ElementTree as xmltree


def publishpageforoledtoxchange():
    """
    publishpageforoledtoxchange - this is to test the OLEDS.PY
    It will send a couple pages to the oled.
    :return:
    """
    try:
        pub = "tcp://%s:%s" % ("172.16.0.10", "5201")
        context = zmq.Context()
        sock_outbound = context.socket(zmq.PUB)  # PUSH
        sock_outbound.linger = 0
        try:
            sock_outbound.bind(pub)
            print("Outbound publisher bind succesfull = %s" % (pub,))
            time.sleep(1)
        except:
            sock_outbound = context.socket(zmq.PUB)
            sock_outbound.connect(pub)
            print("Outbound publisher connect succesfull = %s" % (pub,))
            time.sleep(1)


        #     Topic: OLED.Display. < option > page name / guid
        #     < xmOLEDPage Page = "TestPage" TTL = "60" TStamp = "iso format" >
        #     < RenderText Size = "1" X = "1" Y = "1" Text = "Hello World" / >
        # < / xmOLEDPage >
        systree = xmltree.Element("xmOLEDPage")
        systree.attrib['Page'] = '%s' % "Pub1"
        systree.attrib['TTL'] = "900"
        systree.attrib['TStamp'] = "%s" %datetime.datetime.now()
        renderelm = xmltree.SubElement(systree, "RenderText")
        renderelm.attrib['X'] = "0"
        renderelm.attrib['Y'] = "0"
        renderelm.attrib['Text'] = "012345678901234567890"
        renderelm2 = xmltree.SubElement(systree, "RenderText")
        renderelm2.attrib['X'] = "0"
        renderelm2.attrib['Y'] = "13"
        renderelm2.attrib['Text'] = "Y13 45678901234567890"
        renderelm3 = xmltree.SubElement(systree, "RenderText")
        renderelm3.attrib['X'] = "0"
        renderelm3.attrib['Y'] = "30"
        renderelm3.attrib['Text'] = "Y30 4  YES  890"

        xmlstr = xmltree.tostring(systree, method='xml')
        print(xmlstr)

        sendmsg1  = ["OLED.Display.Test", xmlstr]
        sock_outbound.send_multipart(sendmsg1)
        time.sleep(2)


        for x in range(0, 99):
            sock_outbound.send_multipart(sendmsg1)
            time.sleep(4)


    except Exception as exct:
        print("Outbound exct = %s" % (exct,))



if __name__ == '__main__':
    try:
        publishpageforoledtoxchange()
    except Exception as mainerr:
        print("Main execption occured: %s" %mainerr)
    os._exit(-1)

0 个答案:

没有答案