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 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()
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?
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 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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)
|
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...
|
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...
|
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...
|
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...
|
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(...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |