threading problem

E

Egor Bolonev

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=====================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)
============================
 
S

Steven Bethard

Egor said:
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.
('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:
.... print arg
.... .... func(*args)
....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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top