472,971 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,971 software developers and data experts.

Simple threading example freezes IDLE?

hey all,

For my study I'm writing a simple threaded webcrawler and I am trying
to do this in python. But somehow, using threads causes IDLE to crash
on Windows XP (with the latest python distribution 2.5.1). Even a
simple example such as this:

import thread, time

def doSomething():
print "something"

for i in range(2):
thread.start_new(doSomething, ())

causes IDLE to freeze when I type it in the interpreter. Using the
python command line everything works just fine. Using IDLE on Debian
linux also does not cause anything to crash. What am I overlooking?

regards, Writser Cleveringa

Sep 19 '07 #1
3 5005
I think the -print- command, as used in IDLE, is not thread-safe. I
was bitten by an issue like that today, and the problem ended up being
the -print- command I used.

On the cmd line, it works per-fect-ly.. but IDLE seems to be the culprit.
A possible answer seems to be to write a wrapper for print that makes
it thread safe (with the help of a lock.

On 9/19/07, wr*****@gmail.com <wr*****@gmail.comwrote:
hey all,

For my study I'm writing a simple threaded webcrawler and I am trying
to do this in python. But somehow, using threads causes IDLE to crash
on Windows XP (with the latest python distribution 2.5.1). Even a
simple example such as this:

import thread, time

def doSomething():
print "something"

for i in range(2):
thread.start_new(doSomething, ())

causes IDLE to freeze when I type it in the interpreter. Using the
python command line everything works just fine. Using IDLE on Debian
linux also does not cause anything to crash. What am I overlooking?

regards, Writser Cleveringa

--
http://mail.python.org/mailman/listinfo/python-list
Sep 26 '07 #2
I think I have pinpointed the error:

When the -print- command fills the screen, IDLE crashes. That is, if i
have 30 empty lines before I start to push the current screen upwards,
when the last of those lines is used, and its time to push the screen
upwards, IDLE crashes.

I'm using IDLE 1.2.1, Python 2.5.1, and Tk 8.4. Does anyone has any
idea of why is this happening?

Thanks,
Sergio

Example code --- http://pastebin.com/f21868e26

import time
import Queue
import threading

class Worker(threading.Thread):

def __init__(self, inQueue, **kwds):
threading.Thread.__init__(self, **kwds)
self.inQueue = inQueue
self.setDaemon(True)
self.start()

def run(self):
while True:
item = self.inQueue.get()
print item
self.inQueue.task_done()
time.sleep(0.1)

qSymbols = Queue.Queue()
symbols = range(50)
for symbol in sorted(symbols):
qSymbols.put_nowait(symbol)

Worker(qSymbols) # Start thread
qSymbols.join()
print "The End..."


On 9/26/07, Sergio Correia <se************@gmail.comwrote:
I think the -print- command, as used in IDLE, is not thread-safe. I
was bitten by an issue like that today, and the problem ended up being
the -print- command I used.

On the cmd line, it works per-fect-ly.. but IDLE seems to be the culprit.
A possible answer seems to be to write a wrapper for print that makes
it thread safe (with the help of a lock.

On 9/19/07, wr*****@gmail.com <wr*****@gmail.comwrote:
hey all,

For my study I'm writing a simple threaded webcrawler and I am trying
to do this in python. But somehow, using threads causes IDLE to crash
on Windows XP (with the latest python distribution 2.5.1). Even a
simple example such as this:

import thread, time

def doSomething():
print "something"

for i in range(2):
thread.start_new(doSomething, ())

causes IDLE to freeze when I type it in the interpreter. Using the
python command line everything works just fine. Using IDLE on Debian
linux also does not cause anything to crash. What am I overlooking?

regards, Writser Cleveringa

--
http://mail.python.org/mailman/listinfo/python-list
Sep 26 '07 #3
On Sep 26, 5:01 pm, "Sergio Correia" <sergio.corr...@gmail.comwrote:
>
I'm using IDLE 1.2.1, Python 2.5.1, and Tk 8.4. Does anyone has any
idea of why is this happening?
Two mainloops == bad. IDLE == 1 mainloop. your program == 1
mainloop.

Sep 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Batista, Facundo | last post by:
People, executing the following code from command line, it works as expected (you see "th1 - 2" *always* after "th2 - 2"). But when I execute from IDLE one of two things happens: - Everything...
7
by: Norbert | last post by:
Hello *, i am experimenting with threads and get puzzling results. Consider the following example: #-------------------- import threading, time def threadfunction(): .....print...
15
by: chahnaz.ourzikene | last post by:
Hi all, This is the first i post in this newsgroup, i hope my english is not too bad... Let's get straight to the point ! I have a little probleme using threads in my little training example :...
4
by: Jonathan Fine | last post by:
Hi I'm looking for a simple Python + Tk text editor. I want it as a building block/starting point. I need basic functions only: open a file, save a file, new file etc. It has to be open...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
13
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
4
by: Astley Le Jasper | last post by:
I have an application that put on an old machine with a fresh Xubuntu installation (with Python 2.5). But I can't get the threading to work The application was written on a combination of Windows...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.