Python hangs: Problem with wxPython, threading, pySerial, or events?

Discussion in 'Python' started by Ethan Swint, Oct 15, 2011.

  1. Ethan Swint

    Ethan Swint Guest

    Hi-

    I'm experiencing crashes in my Win32 Python 2.7 application which appear
    to be linked to pyzmq. At the moment, I can't even kill the "python.exe
    *32" process in the Windows Task Manager. At the moment I'm running the
    script using Ipython by calling

    C:\Python27\pythonw.exe "/python27/scripts/ipython-qtconsole-script.pyw"
    -pylab

    but I also experience similar behavior when running within Eclipse.
    I've included an error message at the end which appears in the Windows
    'cmd' window, but the message is not reflected in the pylab window.

    My attached device is transmitting <160><1><2><3><4><80> and is received
    correctly when I run the sample pyserial script 'wxTerminal.py'. In my
    application, however, the message appears to get characters out of order
    or drop bytes.

    If there's a better place to post or if you'd like more info, let me know.

    Thanks,
    Ethan

    ------------------Serial Port Listening
    Thread----------------------------------------
    def MotorRxThread(self):
    """Thread that handles the incoming traffic. Does buffer input and
    generates an SerialRxEvent"""
    while self.alive.isSet(): #loop while alive event is true
    text = self.serMotor.read(1) #read one, with timeout
    if text: #check if not timeout
    n = self.serMotor.inWaiting() #look if there is more to read
    if n:
    text = text + self.serMotor.read(n) #get it
    #log to terminal
    printstring = "MotorRxThread: "
    for b in text:
    printstring += str(ord(b)) + " "
    print printstring
    #pdb.set_trace()
    if self.motorRx0.proc_string(text):
    print "Message: cmd: " + str(self.motorRx0.cmd) + " data: " +
    str(self.motorRx0.data)
    event = SerialRxSpeedEvent(self.GetId(), text)
    self.GetEventHandler().AddPendingEvent(event)
    -----------------\Serial Port Listening
    Thread----------------------------------------

    ----------------Thread
    Start&Stop------------------------------------------------------
    def StartMotorThread(self):
    """Start the receiver thread"""
    self.motorThread = threading.Thread(target=self.MotorRxThread)
    self.motorThread.setDaemon(1)
    self.alive.set()
    self.motorThread.start()

    def StopMotorThread(self):
    """Stop the receiver thread, wait until it's finished."""
    if self.motorThread is not None:
    self.alive.clear() #clear alive event for thread
    self.motorThread.join() #wait until thread has finished
    self.motorThread = None
    self.serMotor.close() #close the serial port connection
    ----------------\Thread
    Start&Stop------------------------------------------------------

    -------------------Error message
    --------------------------------------------------------
    ValueError: '<IDS|MSG>' is not in list
    ([], ['<IDS|MSG>', '', '',
    '{"date":"2011-10-15T10:24:27.231000","username":"kernel","session":"82906c8a-1235-44d0-b65d-
    0882955305c1","msg_id":"7cfcd155-bc05-4f47-9c39-094252223dab","msg_type":"stream"}',
    '{"date":"2011-10-15T10:24:27.23100
    0","username":"kernel","session":"82906c8a-1235-44d0-b65d-0882955305c1","msg_id":"f4b88228-b353-4cfb-9bbe-ae524ee1ac38",
    "msg_type":"stream"}',
    '{"date":"2011-10-15T10:24:00.774000","username":"username","session":"9f393860-c2ab-44e9-820d-8f
    08ae35044e","msg_id":"13a46e93-8da2-487b-ab12-6cae47b1ac34","msg_type":"execute_request"}',
    '{"date":"2011-10-15T10:24:0
    0.774000","username":"username","session":"9f393860-c2ab-44e9-820d-8f08ae35044e","msg_id":"13a46e93-8da2-487b-ab12-6cae4
    7b1ac34","msg_type":"execute_request"}', '{"data":"\\nMotorRxThread: 0
    MotorRxThread: 4 ","name":"stdout"}'])
    ERROR:root:Exception in I/O handler for fd <zmq.core.socket.Socket
    object at 0x03ADFCC0>
    Traceback (most recent call last):
    File
    "C:\Python27\lib\site-packages\pyzmq-2.1.9-py2.7-win32.egg\zmq\eventloop\ioloop.py",
    line 291, in start
    self._handlers[fd](fd, events)
    File
    "C:\Python27\lib\site-packages\pyzmq-2.1.9-py2.7-win32.egg\zmq\eventloop\stack_context.py",
    line 133, in wrapped
    callback(*args, **kwargs)
    File "C:\Python27\lib\site-packages\IPython\zmq\kernelmanager.py",
    line 448, in _handle_events
    self._handle_recv()
    File "C:\Python27\lib\site-packages\IPython\zmq\kernelmanager.py",
    line 458, in _handle_recv
    ident,msg = self.session.recv(self.socket)
    File "C:\Python27\lib\site-packages\IPython\zmq\session.py", line
    585, in recv
    raise e
    ValueError: No JSON object could be decoded
    ERROR:root:Exception in I/O handler for fd <zmq.core.socket.Socket
    object at 0x03ADFCC0>
    Traceback (most recent call last):
    File
    "C:\Python27\lib\site-packages\pyzmq-2.1.9-py2.7-win32.egg\zmq\eventloop\ioloop.py",
    line 291, in start
    self._handlers[fd](fd, events)
    File
    "C:\Python27\lib\site-packages\pyzmq-2.1.9-py2.7-win32.egg\zmq\eventloop\stack_context.py",
    line 133, in wrapped
    callback(*args, **kwargs)
    File "C:\Python27\lib\site-packages\IPython\zmq\kernelmanager.py",
    line 448, in _handle_events
    self._handle_recv()
    File "C:\Python27\lib\site-packages\IPython\zmq\kernelmanager.py",
    line 458, in _handle_recv
    ident,msg = self.session.recv(self.socket)
    File "C:\Python27\lib\site-packages\IPython\zmq\session.py", line
    579, in recv
    idents, msg_list = self.feed_identities(msg_list, copy)
    File "C:\Python27\lib\site-packages\IPython\zmq\session.py", line
    609, in feed_identities
    idx = msg_list.index(DELIM)
    ValueError: '<IDS|MSG>' is not in list
    ---------------------------------------------------------------------------
    ZMQError Traceback (most recent call last)
    C:\Users\Ethan\<string> in <module>()

    C:\Python27\lib\site-packages\IPython\zmq\ipkernel.pyc in main()
    671 """Run an IPKernel as an application"""
    672 app = IPKernelApp.instance()
    --> 673 app.initialize()
    674 app.start()
    675

    C:\Python27\lib\site-packages\IPython\zmq\ipkernel.pyc in
    initialize(self=<IPython.zmq.ipkernel.IPKernelApp object>, arg
    v=None)
    604 )
    605 def initialize(self, argv=None):
    --> 606 super(IPKernelApp, self).initialize(argv)
    607 self.init_shell()
    608 self.init_extensions()

    C:\Python27\lib\site-packages\IPython\zmq\kernelapp.pyc in
    initialize(self=<IPython.zmq.ipkernel.IPKernelApp object>, ar
    gv=None)
    213 self.init_session()
    214 self.init_poller()
    --> 215 self.init_sockets()
    216 self.init_io()
    217 self.init_kernel()

    C:\Python27\lib\site-packages\IPython\zmq\kernelapp.pyc in
    init_sockets(self=<IPython.zmq.ipkernel.IPKernelApp object>)
    148
    149 self.shell_socket = context.socket(zmq.XREP)
    --> 150 self.shell_port = self._bind_socket(self.shell_socket,
    self.shell_port)
    151 self.log.debug("shell XREP Channel on port:
    %i"%self.shell_port)
    152

    C:\Python27\lib\site-packages\IPython\zmq\kernelapp.pyc in
    _bind_socket(self=<IPython.zmq.ipkernel.IPKernelApp object>,
    s=<zmq.core.socket.Socket object>, port=50104)
    137 port = s.bind_to_random_port(iface)
    138 else:
    --> 139 s.bind(iface + ':%i'%port)
    140 return port
    141

    C:\Python27\lib\site-packages\pyzmq-2.1.9-py2.7-win32.egg\zmq\core\socket.pyd
    in zmq.core.socket.Socket.bind (zmq\core\s
    ocket.c:4527)()

    ZMQError: Address in use
    ---------\ERROR MESSAGE--------------------------------------------------
    Ethan Swint, Oct 15, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Holger Joukl
    Replies:
    0
    Views:
    425
    Holger Joukl
    Apr 23, 2004
  2. John Nagle
    Replies:
    1
    Views:
    621
    Ned Deily
    Nov 8, 2009
  3. Ethan Swint
    Replies:
    0
    Views:
    562
    Ethan Swint
    Oct 17, 2011
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    354
    Chris
    Aug 30, 2005
  5. Tim Shadel

    Gem hangs => TCPSocket.write hangs

    Tim Shadel, Jul 23, 2005, in forum: Ruby
    Replies:
    1
    Views:
    382
    Ville Mattila
    Jul 24, 2005
Loading...

Share This Page