You won't be able to throttle your socket send rate, the only solution will be to limit the call to your sending socket.
First, what you'll have to do here, is to put the received data in a container (take a look to the python Queues), then, you'll have to schedule your sending process. You could use a Timer for this.
What it could looks like would be :
class Exchange(object):
def __init__(self):
#create the queue
#create the sockets
def receive_every_seconds_method(self):
# Here we put the received data into the queue
self.the_queue.put(self.receiving_socket.recv())
def send_data_later(self):
while not self.the_queue.empty():
self.emission_socket.send(self.the_queue.get())
# reschedule
self.schedule()
def schedule(self, timeout=30):
self.timer = Timer(timeout, self.send_data_later)
self.timer.start()
def run(self):
self.schedule(30)
while self.continue_the_job: #this is the stop condition
self.receive_every_seconds_method()
time.sleep(1)
This way, you will be able to send data every 30 seconds (if there are data to send)