python, pyserial, & zombies (beginner)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • turtleRider
    New Member
    • Mar 2008
    • 1

    #1

    python, pyserial, & zombies (beginner)

    Hi,
    I am new to Python and non-web programming. I am using pySerial in OSX 10.5.2 (Python 2.5) to access a bluetooth module that is mapped to a device file.

    I can access the device with screen /dev/tty.BTdevice 115200 and I correctly get a stream of 3 digit numbers (data from a sensor). I wrote a Python script to read the numbers and print them.

    My problem comes when I have a bug in my program or I don't close the serial object in the interactive mode, the terminal window freezes. If I press ctrl-C, it displays ^C and same with ctrl-D. A kill -9 <PID> doesn't do anything so it seems like a zombie process. I can close the terminal window, but the Python process gets a PPID of 1 and is still not able to be killed. If I ignore it and try screen /dev/tty.BTdevice 115200, screen freezes immediately (ctrl-A,ctrl-\ has no effect to exit the screen program). It seems the zombie process is holding the device file. The only fix I've found is to restart the computer. This is a drag for development.

    Any thoughts? is it an OSX problem? I haven't been able to find much about problems with developing python with bluetooth/pyserial in OSX.
    Any help is greatly appreciated!
    thanks,
    Jeff
  • Subsciber123
    New Member
    • Nov 2006
    • 87

    #2
    You should probably use "try/finally" blocks around all the code starting with when you get a handle on the device. For example:
    [CODE=python]try:
    f=open("/dev/whatever")
    doStuff(f)
    finally:
    f.close()[/CODE]
    or you could use the new "with" block, but I personally don't like that syntax because there are other ways to do it that already exist in the language.

    Comment

    Working...