views:

127

answers:

4

I'm trying to add multithreading to a Python app, and thus started with some toy examples :

import threading

def myfunc(arg1, arg2):
     print 'In thread'
     print 'args are', arg1, arg2

thread = threading.Thread(target=myfunc, args=('asdf', 'jkle'))

thread.start()
thread.join()

This works beautifully, but as soon as I try to start a second thread, I get a RuntimeError :

import threading

def myfunc(arg1, arg2):
     print 'In thread'
     print 'args are', arg1, arg2

thread = threading.Thread(target=myfunc, args=('asdf', 'jkle'))
thread2 = threading.Thread(target=myfunc, args=('1234', '3763763é'))

thread.start()
thread2.start()

thread.join()
thread2.join()

As others seems to have no problem running this code, let me add that I am on Windows 7 x64 Pro with Python 2.6.3 32bits (if that matters).

+1  A: 
thread2 = threading.Thread(target=myfunc, args=('1234', '3763763é'))

Are you declaring the file as UTF-8?-----------------------------------------------------^

Jeff Ober
iso-8859-1, but that's not the problem ;)...
Wookai
+1  A: 

Can you post the exact error you get?

Runs fine for me (after replacing the é character with an e):

In thread
args areIn thread
asdfargs are  jkle1234
 3763763e

If I leave the original script you posted and save the file as UTF-8 with BOM on Windows:

In thread
args areIn thread
asdfargs are  jkle1234
 3763763é

Saving the code you posted as ASCII results in a SyntaxError:

SyntaxError: Non-ASCII character '\xe9' in file threadtest.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

Environment information:

C:\python -V
Python 2.6.2
C:\cmd
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

matt b
The problem is not the special char. The error I get is a popup saying "Runtime Error", probably from IDLE itself, and then it crashes.
Wookai
And are there any details of the RuntimeError? We can't solve your problem if you hold back information.
matt b
Sorry, I'm not holding any information. The only message I get is this alert window from IDLE saying 'Runtime error', and that's it. I guess the problem comes from IDLE, as the same code run directly from the command line works fine.
Wookai
Perhaps your IDLE installation is screwed up? Might be worth an attempt at upgrading/reinstalling.
matt b
A: 

As said in the comments, I think that the problem comes from IDLE itself, and not from my code. Thanks for your help anyway !

I upvoted your answers but will be accepting mine, as there is no real solution to this problem.

Wookai
A: 

Maybe it is because you have the same filename or project name like "threading" or "Thread" under some directory and you have runned it once since this bootup.

Pinglei