473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

threading problem

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
2 2942
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
17
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next...
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...
11
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
5
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.