473,396 Members | 2,092 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,396 software developers and data experts.

passing argumetns to threading.Thread

I'm trying to pass arguments to my the run method of my class that
inherits from threading.Thread.

class Reader(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self, None, None, None, (conn))

def run(self,conn):
while 1:
data = conn.recv(1024)
print data

Jul 18 '05 #1
4 7854
sashan wrote:
I'm trying to pass arguments to my the run method of my class that
inherits from threading.Thread.

class Reader(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self, None, None, None, (conn))

def run(self,conn):
while 1:
data = conn.recv(1024)
print data

woops left out some stuff...

later in the program:

t = Reader(conn)
t.start()

Jul 18 '05 #2
sashan wrote:
sashan wrote:
I'm trying to pass arguments to my the run method of my class that
inherits from threading.Thread.

class Reader(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self, None, None, None, (conn))
def run(self,conn): while 1:
data = conn.recv(1024)
print data

woops left out some stuff...

later in the program:

t = Reader(conn)
t.start()

sorry ... i keep hitting the wrong shortcut key combom when sending
these messages resulting in truncations

Anyway after t.start() I get an error message basically saying:
TypeError: 2 arguments expected for Reader.run (1 given)

How do I resolve this?
Jul 18 '05 #3
sashan wrote:

I'm trying to pass arguments to my the run method of my class that
inherits from threading.Thread.

class Reader(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self, None, None, None, (conn))

def run(self,conn):
while 1:
data = conn.recv(1024)
print data


You can't pass run() arguments.

You can, however, use instance variables since Reader is an object:

class Reader(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self) # no need for extra args
self.conn = conn

def run(self):
while 1:
data = self.conn.recv(1024)
print data

-Peter
Jul 18 '05 #4
You can, however, use instance variables since Reader is an object:

class Reader(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self) # no need for extra args
self.conn = conn

def run(self):
while 1:
data = self.conn.recv(1024)
print data

-Peter


Thanks

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christopher J. Bottaro | last post by:
Hello, I'm new to Python programming, so please excuse me. thread = threading.Thread(self.somefunc()) thread.start() print "Thread started" def somefunc(self): while (1)
2
by: Egor Bolonev | last post by:
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...
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...
3
by: rollasoc | last post by:
Hi, Having a slight problem with how to pass parameters to functions between threads. I have a form with a progress bar and a description label on it. It has a public function...
0
by: Eric Sabine | last post by:
OK, I'm trying to further my understanding of threading. The code below I wrote as kind of a primer to myself and maybe a template that I could use in the future. What I tried to do was pass data...
10
by: ChrisB | last post by:
Coming from a C/C++ background, how would I pass a function pointer to a function? I want to write a function that handles certain thread spawning. Here's what I'm trying to invision: function(...
3
by: brian_harris | last post by:
I am tring to start a thread where I am passing info into thread. According to MS documentation I must do this by creating a class for that thread. I have done this but am getting a compiler...
2
by: Adam Mullins | last post by:
Hello, I'm writing a physics simulator back-end with a built-in, threaded server that for the moment is quite simple. I've faced a few problems in writing this code, however, as it's the first time...
6
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.