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): class pyserv(threading.Thread): def __init__(self,(socket,address)): threading.Thread.__init__(self) self.SOCKET=socket self.ADDRESS=address def run(self): ... (irrelevant code here, receive data from socket, byteswap, prepare format string for unpacking below, etc.) ... figure(count) dataArray = array(struct.unpack(format,data)) plot(dataArray) show() self.SOCKET.close() count = 1 s = socket(AF_INTER,SOCK_STREAM) s.bind(appropriate options here) s.listen(10) print 'server running' while True: pyserv(s.accept()).start() 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, Dan ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users