From: Daniel Hearn <dphearn@gm...> - 2007-09-18 21:07:20
Hi. I wrote a socket server in python that accepts up to two data
arrays and should plot them using matplotlib. Unfortunately, when I
made my server multi-threaded I ran into some very strange issues. I
can't figure out what exactly is happening so I can't fix it. If anyone
knows what is going on/why it isn't working, please let me know.
Here is a code snippet (showing what happens when only one data array is
passed to it):
(irrelevant code here, receive data from socket,
byteswap, prepare format string for
unpacking below, etc.)
dataArray = array(struct.unpack(format,data))
count = 1
s = socket(AF_INTER,SOCK_STREAM)
s.bind(appropriate options here)
print 'server running'
count += 1
Scenario A: When I run this and send one set of data, it plots just
fine. Subsequent data sets never plot, it opens up a new window as if
it wants to plot something and then hangs.
Scenario B: When I run this and send one set of data, view it, and then
close it, I can send another data set. It opens up a figure, plots it,
and then closes immediately afterwards with no interaction on my part.
If I put a sleep command after the show(), like sleep(5),it will stay up
for 5 seconds and then close.
Scenario C: If I plot the data but do not show it until after the while
loop, I get the same results as in scenario A.
Is it breaking because I can't use multiple show() commands? Does
matplotlib not play nice with threads or something, or am I just not
implementing threads correctly (first time w/ python using threads)?
Data arrays being passed are just character/integer/float arrays. I am
using an array from numpy to unpack data from the struct. Let me know
if you need more info. Thanks,