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

recursive method in __init__

hi all,

I thought it would be nice to have instances that can "live" somehow in
the "background" and do some tasks without being told so. The problem in
the code below is: calling new_host = Host(ip, mac, collector) never
"returns" because the the self.update() method gets called recursively.
Im pretty sure I have to restructure the code and call the update()
method from outside but I ask out of curiosity and to get some ideas how
to do such things elegantly.

thanks
Paul

class Host(object):
def __init__(self, ip, mac, collector):
'''ip and mac are strings, collector is a Collector() class
instance from the loganalyze module'''
re_ip = re.compile ('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
print "New host instance created"
if not re_ip.match(ip):
raise ValueError('Invalid IP address.')
else:
self._ip_addr = ip
self._mac_addr = mac
self.collector = collector
# traffic counter
self._minutes = []
self._additional_ips = []
self.update()

def update(self):
'''adds a dict with traffic for this host every minute'''
print "Method update of class Host called"
data = self.collector.get(self._ip_addr)
if data:
self.minutes.append(data)
time.sleep(60)
self.update()
Jul 18 '05 #1
0 953

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

Similar topics

8
by: Paul Chiusano | last post by:
I've been playing around with generators and have run into a difficulty. Suppose I've defined a Node class like so: class Node: def __init__(self, data=None, left=None, right=None):...
12
by: Donnal Walter | last post by:
The following method is defined in one of my classes: def setup(self, items={}): """perform setup based on a dictionary of items""" if 'something' in items: value = items # now do something...
3
by: Chris S. | last post by:
Why do most, if not all, compound Python structures not convert their elements to strings recursively? >>> class foo: .... def __init__(self, a): .... self.a = a .... def...
3
by: Bernie | last post by:
#!/usr/bin/env python import sys import copy ''' How to define __deepcopy__ with out causing recursive calls to copies of self? Bernie Day 01/25/05
13
by: Pelmen | last post by:
How can I get rid of recursive call __getattr__ inside this method, if i need to use method or property of the class?
4
by: Gregory Piñero | last post by:
Hi, Would anyone be able to tell me why my function below is getting stuck in infinite recusion? Maybe I'm just tired and missing something obvious? def...
2
by: sebastien.abeille | last post by:
Hello, I would like to create a minimalist file browser using pyGTK. Having read lot of tutorials, it seems to me that that in my case, the best solution is to have a gtk.TreeStore containing...
4
by: Erik Jones | last post by:
Say you're given a call event frame for a method call. How can you tell if the code being executed came from a super class of the object or class the method was called on? Erik Jones ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.