For every x amount of messages sent wait x amount of time and continue
MATTHEWBECHTEL (123)

Is there a way to make it so for example, you send 1000 messages per second and you send the first 1000 messages to then wait like 1 second and continue?

You are viewing a single comment. View All
ArchieMaclean (750)

I'm not quite sure what the question is?
I think what you want is to send 1000 messages in 1 second, then wait 1 second, and repeat? If so, you could have something like this:

import time

while True:  # repeats forever
  number_of_times = 1000
  for each in xrange(number_of_times):
    # send message


    # this will wait 1/number_of_times seconds - if you do 
    # this number_of_times times, then it will add up to 1 second
    time.sleep(1/number_of_times)


  # then wait 1 second before starting again
  time.sleep(1)

Please correct me if I've misunderstood, or upvote if this helps :)

MATTHEWBECHTEL (123)

Yes you are correct. I have the sending a thousand messages per second part down but I need to add waiting a second and repeating. It seems your code does not work. It needs to wait one second every thousand messages to not crash. @ArchieMaclean

ArchieMaclean (750)

@MATTHEWBECHTEL you can remove that bit if you want (the last time.sleep(1).
Also, I should have put xrange above, not range. I have changed it.

MATTHEWBECHTEL (123)

Ok thanks. But I sort of need to keep the wait 1 second in the loop.
@ArchieMaclean

ArchieMaclean (750)

@MATTHEWBECHTEL Why were you saying my code wasn't working? What isn't right?
I'm not accusing, just wondering what you wanted to change.

MATTHEWBECHTEL (123)

Oh I’m so sorry I did something wrong it was my mistake not your code. I just realized. @ArchieMaclean

MATTHEWBECHTEL (123)

I’m probably doing something wrong but it says xrange is not defined. @ArchieMaclean

ArchieMaclean (750)

@MATTHEWBECHTEL what version of python are you using?

ArchieMaclean (750)

@MATTHEWBECHTEL That should work - do you have a link to the repl?

ArchieMaclean (750)

@MATTHEWBECHTEL That's very strange. When I copied the code into another repl it worked, but forking it didn't. Hmm
Try just copying the code into another repl?

ArchieMaclean (750)

@ArchieMaclean Actually, I just realised Python3 doesn't support xrange :| Just use range instead.
Sorry, I'm used to python2

MATTHEWBECHTEL (123)

It does or come up with an error now, but nothing happens now. @ArchieMaclean

ArchieMaclean (750)

@MATTHEWBECHTEL That's because you're not doing anything apart from looping.
Try replacing

# send message

with something like

print("Hello, World!")

(This will cause it to crash though, so you may want to replace the while True with something like for n in range(5). Even so, it will probably take longer than 1 second just because print takes too long to execute)

MATTHEWBECHTEL (123)

Ok I will try it later because I will be busy for a hour or two. Thank you so much. Your the most helpful person to me on Repl. @ArchieMaclean

MATTHEWBECHTEL (123)

File “main.py”, line 6. Print(“Hello, World!”). SyntaxError: invalid character in identifier. @ArchieMaclean

MATTHEWBECHTEL (123)

Never mind. I fixed it. All I had to do was change ”Hello, World!” To "Hello, World!”@MATTHEWBECHTEL