[triangle-zpug] blocking threads and capturing control-c

Lee Nelson lee_nelson at ncsu.edu
Mon Jan 28 14:54:26 UTC 2008


I am still working on using Python to connect my lab's data acquisition
hardware to a program called RBNB or Data Turbine.  As David suggested, I am
now converting the existing fake_daq program from c to python.  As of now I
have two main questions / problems:

 

The first problem is that my threads seem to "hang" the interpreter and I
have to forcefully shut it down.  I have two threads I am trying to start
and whichever one I try to start first, the interpreter hangs and the second
one never starts.  I've done some research but I'm hoping somebody can tell
me if I am on the right track or if there is something else I should be
looking for.  I found this post on python.org  which seems similar to what I
am experiencing: 

 

http://mail.python.org/pipermail/python-list/2001-April/080386.html 

 

After reading this I started to look for any calls that could be blocking
and causing the interpreter to hang.  I think most of the calls I'm making
shouldn't affect the interpreter's ability to switch threads but I've been
trying to make them all non-blocking anyway.  So far I've tried to make all
of the socket calls non-blocking by using the select() function to check the
port before sending data.  I also switched to Queue.put_nowait() and
Queue.get_nowait().  I am using time.strftime() but I don't think this would
block the interpreter.  In one of the threads I use a function which
accesses a shared variable to see which channels are active.  This function
has to acquire a lock before accessing the shared data so this could
potentially be a problem . but this is only used in one of the threads and
both of them seem to be hanging.  

 

The second question / problem relates to closing down my program.   The C
code that I am basing my Python code on is setup to capture a keyboard
interrupt event (ie control-c or control-break) which it uses to stop
streaming data, issue a "Daq Stop" event to data turbine, and properly close
down the sockets.  How can I capture this event in my Python code?  I looked
at different options using try and except but I never could get anything to
work correctly.  It seems that by using try, I will only capture the event
if the code related to the try statement is running.  I want to capture the
event no matter what part of the code is running.  Is there an easy way to
do this?

 

My Python code and an executable java program which was written to validate
the communication protocol can be downloaded here:

 

http://www.cfl.ncsu.edu/temp/CFL_Daq.py

 

http://www.cfl.ncsu.edu/temp/dndtester.jar

 

Thanks,

 

Lee

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://starship.python.net/pipermail/triangle-zpug/attachments/20080128/80f26556/attachment.htm 


More information about the triangle-zpug mailing list