April 4th, 2005, 06:44 PM
I'm having a bit of a problem with organizing my loops. I have one main loop, which is always receiving bytes (through a socket) from Battle.net. Meanwhile, if a user who has access on the bot (my program) requests the bot to run a certain command, the bot adds this command to the Queue (a basic Queue which waits 3-5 seconds to send a message, depending on how long it is), I will then start a loop to determine when the current time is 3-5 seconds after the time that the item got added to the queue, I do not want to use time.sleep() because I still wish to receiving data from Battle.net. Here is what I currently have:
The non stop loop receiving data from Battle.net
#code code code
I've noticed if I do it this way, the Queue will not send the message until the while True: loop receives 1024 bytes, is there a way to run the other loop first? And then continue the while True: loop? Or should the queue have while True: and the data received from Battle.net be using while 1:? Thanks.
s.recv(1024) # briefly description what the code looks like
April 5th, 2005, 02:26 AM
No idea on the blocking read - possibly need to insert a sleep call...
As far as while loops go, you can stick anything which evaluates as True (1, True, "False", [False], etc). using "while True:" is customary in modern python code, though.
April 5th, 2005, 12:01 PM
Well I understand that you mean running one loop and then the other. Just do something like:
The only bad thing about that way is to add a "break" in the first loop after the second.
code code code
Hope it helps tell me if it is not the way you want it
April 5th, 2005, 02:52 PM
I'm sorry if the first time I wasn't clear enough. I do not want to use sleep(), I wish to still receive data from Battle.net. I want the loop that receives data from Battle.net to keep running, when I go to start the next loop, when the second loop starts, at the given time, it will send the message to Battle.net, and break itself. Then the original loop which receives data from Battle.net should continue going. This is why I was wondering if I should use while 1: for receiving data, and while True: for the sending of the message to Battle.net. If they are both while True:, it creates a problem.
April 5th, 2005, 02:55 PM
Ya since <-1,1> = True and 0 = False
They are identical
April 5th, 2005, 02:58 PM
I know this, but someone once told me that while 1: will (I can't remember word for word, just the basis of the idea) will stop the while True: loop and run its own loop, once it is broken, the other will continue on with its work.