TypeError: unbound method must be called with class instance 1st argument

G

Guest

I'm a novice at Python, and found some code samples on how to use
threads. My script is being run by a product that contains a Jython
interpreter. Can someone please explain why I get the following error:

Traceback (innermost last):
File "/full/path/to/file/GenerateData.py", line 104, in ?
File "/full/path/to/file/GenerateData.py", line 34, in __init__
TypeError: unbound method must be called with class instance 1st
argument


Here are the important pieces of my GenerateData.py script. Note that
"scriptinterface" is something provided by the product to allow my
script to interface with it. Line 104 is the last line -- the one that
creates a GenThread and calls start() on it.


import sys

# need this section otherwise the import random won't work
if sys.path.count('/usr/local/lib/python2.2/') == 0:
sys.path.append('/usr/local/lib/python2.2/')

import random
import time
import threading

from java.lang import String
from jarray import array

class GenThread(threading.Thread):
def __init__(self, ipAddress, port):
threading.Thread.__init__()
self.ipAddress = ipAddress
self.port = str(port)

def run(self):
#
# code
#

GenThread(scriptinterface.getSnmpIPAddress(),
scriptinterface.getSnmpPort()).start()
 
M

Matimus

Can someone please explain why I get the following error:

The following line:
threading.Thread.__init__()
Should be written as:
threading.Thread.__init__(self)
 

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,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top