X-Spam-Check-By: sourceware.org Message-ID: <46D8A577.1060908@kleckner.net> Date: Fri, 31 Aug 2007 16:34:15 -0700 From: Jim Kleckner User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Threading issue in cygwin python 2.5.1-2 ? Content-Type: multipart/mixed; boundary="------------020606010004060205070905" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------020606010004060205070905 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I get an exception running a Python example that uses threads that I downloaded from the net (ASPN): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 This may just be another case of "threading doesn't work well". I'm including the test case. It fails with cygwin Python with a dialog that says: The instruction as "0x0000000001" referenced memory at "0x00000000". The memory could not be "written". gdb doesn't seem to give any enlightenment. Would someone mind giving this example a try and, if it works for you on a current cygwin, post back to the list? If so, I'll include cygcheck output. This is the version that is failing: Cygwin current Python: Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Here are configurations that aspn.py does work: Stock 2.4 Windows Python: Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Stock 2.5 Windows Python: Microsoft Windows XP [Version 5.1.2600] Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Ubuntu Dapper: Python 2.4.3 (#2, Oct 6 2006, 07:52:30) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Ubuntu Edgy: Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2 --------------020606010004060205070905 Content-Type: text/plain; name="aspn-threading-tkinter.py" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="aspn-threading-tkinter.py" # From http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 """ This recipe describes how to handle asynchronous I/O in an environment where you are running Tkinter as the graphical user interface. Tkinter is safe to use as long as all the graphics commands are handled in a single thread. Since it is more efficient to make I/O channels to block and wait for something to happen rather than poll at regular intervals, we want I/O to be handled in separate threads. These can communicate in a threasafe way with the main, GUI-oriented process through one or several queues. In this solution the GUI still has to make a poll at a reasonable interval, to check if there is something in the queue that needs processing. Other solutions are possible, but they add a lot of complexity to the application. Created by Jacob Hall?n, AB Strakt, Sweden. 2001-10-17 """ import Tkinter import time import threading import random import Queue class GuiPart: def __init__(self, master, queue, endCommand): self.queue = queue # Set up the GUI console = Tkinter.Button(master, text='Done', command=endCommand) console.pack() # Add more GUI stuff here def processIncoming(self): """ Handle all the messages currently in the queue (if any). """ while self.queue.qsize(): try: msg = self.queue.get(0) # Check contents of message and do what it says # As a test, we simply print it print msg except Queue.Empty: pass class ThreadedClient: """ Launch the main part of the GUI and the worker thread. periodicCall and endApplication could reside in the GUI part, but putting them here means that you have all the thread controls in a single place. """ def __init__(self, master): """ Start the GUI and the asynchronous threads. We are in the main (original) thread of the application, which will later be used by the GUI. We spawn a new thread for the worker. """ self.master = master # Create the queue self.queue = Queue.Queue() # Set up the GUI part self.gui = GuiPart(master, self.queue, self.endApplication) # Set up the thread to do asynchronous I/O # More can be made if necessary self.running = 1 self.thread1 = threading.Thread(target=self.workerThread1) self.thread1.start() # Start the periodic call in the GUI to check if the queue contains # anything self.periodicCall() def periodicCall(self): """ Check every 100 ms if there is something new in the queue. """ self.gui.processIncoming() if not self.running: # This is the brutal stop of the system. You may want to do # some cleanup before actually shutting it down. import sys sys.exit(1) self.master.after(100, self.periodicCall) def workerThread1(self): """ This is where we handle the asynchronous I/O. For example, it may be a 'select()'. One important thing to remember is that the thread has to yield control. """ while self.running: # To simulate asynchronous I/O, we create a random number at # random intervals. Replace the following 2 lines with the real # thing. time.sleep(rand.random() * 0.3) msg = rand.random() self.queue.put(msg) def endApplication(self): self.running = 0 rand = random.Random() root = Tkinter.Tk() client = ThreadedClient(root) root.mainloop() --------------020606010004060205070905 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --------------020606010004060205070905--