error: argument after ** must be a dictionary

A

abcd

I have class like this...

import threading
class MyBlah(object):
def __init__(self):
self.makeThread(self.blah, (4,9))

def blah(self, x, y):
print "X and Y:", x, y

def makeThread(self, func, args=(), kwargs={}):
threading.Thread(target=self.blah, args=args,
kwargs=kwargs).start()

When I do...
b = MyBlah()

I am getting this error:
TypeError: MyBlah object argument after ** must be a dictionary

What am I missing?
 
F

Fredrik Lundh

abcd said:
I have class like this...

import threading
class MyBlah(object):
def __init__(self):
self.makeThread(self.blah, (4,9))

def blah(self, x, y):
print "X and Y:", x, y

def makeThread(self, func, args=(), kwargs={}):
threading.Thread(target=self.blah, args=args,
kwargs=kwargs).start()

When I do...
b = MyBlah()

I am getting this error:
TypeError: MyBlah object argument after ** must be a dictionary

I'm getting

X and Y: 4 9

are you sure you posted the right code ?

where's the rest of the traceback, btw ?

</F>
 
B

bruno at modulix

abcd said:
I have class like this...

import threading
class MyBlah(object):
def __init__(self):
self.makeThread(self.blah, (4,9))

def blah(self, x, y):
print "X and Y:", x, y

def makeThread(self, func, args=(), kwargs={}):
threading.Thread(target=self.blah, args=args,
kwargs=kwargs).start()

Shouldn't it be:

def makeThread(self, func, *args, **kwargs):
threading.Thread(target=self.blah,
*args,
**kwargs).start()
 
K

Kent Johnson

bruno said:
Shouldn't it be:

def makeThread(self, func, *args, **kwargs):
threading.Thread(target=self.blah,
*args,
**kwargs).start()

No. threading.Thread() doesn't use *args, **kwargs, it uses explicit
named parameters.

Kent
 
A

abcd

Not sure if it matters, but this occurs when running a unittest.

The trace back is:
Traceback (most recent call last):
File "C:\Python24\Lib\threading.py", line 442, in __bootstrap
self.run()
File "C:\Python24\Lib\threading.py", line 422, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: MyTestCase object argument after ** must be a dictionary

Unhandled exception in thread started by <bound method
backendCmd._getIncomingDataPacket of <dbgp.client.backendCmd instance
at 0x00B28B70>>
 

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

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top