By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

threading problem

P: n/a
hi all

my program terminates with error i dont know why it tells 'TypeError:
run() takes exactly 1 argument (10 given)'

=program====================
import os, os.path, threading, sys

def get_all_files(path):
"""return all files of folder path, scan with subfolders
"""
if len(path) > 0:
if path[-1] == ':':
path=path+'\\'
try:
for i in os.listdir(path):
j = os.path.join(path, i)
if os.path.isdir(j):
for ii in get_all_files(j):
yield ii
if os.path.isfile(j):
yield j
except:pass

#----------------

lock1 = threading.Lock()

def run(path):
for i in get_all_files(path):
lock1.acquire()
print i
lock1.release()

#----------------

for path in os.listdir('c:\\'):
if os.path.isdir(os.path.join('c:\\', path)):
threading.Thread(target = run, args = (os.path.join('c:\\',
path))).start()
else:
lock1.acquire()
print path
lock1.release()
============================


=output=====================
================================ RESTART
================================
AUTOEXEC.BAT
boot.iniException in thread Thread-1:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (10 given)
Bootfont.bin
BOOTLOG.PRV
BOOTLOG.TXT
BOOTSECT.DOS
COMMAND.COM
CONFIG.SYS
DETLOG.TXT
devicetable.log
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (25 given)

FRUNLOG.TXT
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (9 given)

hsf5442.sys
Exception in thread Thread-4:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (10 given)

IO.SYS
LOGO.SYS
MSDOS.---
MSDOS.SYS
netldx.vxd
NETLOG.TXT
NHL2005.mdf
NHL2005.mds
ntdetect.com
ntldr
Exception in thread Thread-5:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (9 given)

PAGEFILE.SYS
Exception in thread Thread-6:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (16 given)

Exception in thread Thread-7:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (11 given)

Exception in thread Thread-8:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (11 given)

Exception in thread Thread-9:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (11 given)

rew.ini
Exception in thread Thread-10:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (10 given)

SETUPLOG.TXT
SUHDLOG.DAT
Exception in thread Thread-11:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (28 given)

SYSTEM.1ST
Exception in thread Thread-12:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (7 given)

Exception in thread Thread-13:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (7 given)

Exception in thread Thread-14:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (10 given)

Exception in thread Thread-15:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (8 given)

~WRD0003.tmp
Exception in thread Thread-16:
Traceback (most recent call last):
File "C:\Python23\lib\threading.py", line 436, in __bootstrap
self.run()
File "C:\Python23\lib\threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: run() takes exactly 1 argument (16 given)

============================
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Egor Bolonev wrote:
hi all

my program terminates with error i dont know why it tells 'TypeError:
run() takes exactly 1 argument (10 given)' [snip] threading.Thread(target = run, args = (os.path.join('c:\\',
path))).start()


I believe the args argument to threading.Thread is supposed to be a
sequence.
import os
path = 'directory'
os.path.join('c:\\', path) 'c:\\directory' (os.path.join('c:\\', path)) 'c:\\directory' (os.path.join('c:\\', path),) ('c:\\directory',)

I think if you change the call to look like:

threading.Thread(target=run, args=(os.path.join('c:\\', path),)).start()

or

threading.Thread(target=run, args=[os.path.join('c:\\', path)]).start()

then you should be okay. You're probably getting the 10 argument
message because your string is 10 characters long and threading.Thread
is treating each character in your string as an argument:
def f(arg): .... print arg
.... def g(func, args): .... func(*args)
.... g(f, 'abcdefghij')

Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 2, in g
TypeError: f() takes exactly 1 argument (10 given)

Steve
Jul 18 '05 #2

P: n/a
On Fri, 10 Dec 2004 00:12:16 GMT, Steven Bethard
<st************@gmail.com> wrote:
I think if you change the call to look like:

threading.Thread(target=run, args=(os.path.join('c:\\', path),)).start()


oh i see now. thanks
s='sdgdfgdfg'
s == (s) True s == (s,) False

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.