Home > other >  Python Help Loop Stop
Python Help Loop Stop

Time:04-23

try:
    req = r.post(URI, headers=headers, data=Data, stream=True, verify=False)
    try:
        if req.json()["status_code"] == 0:
            impr_id = req.json()["log_pb"]["impr_id"]
            TotalSendedShare  = 1
            if DebugMode:
                print(Colorate.Horizontal(Colors.yellow_to_red, f"Shared Amount: {TotalSendedShare})"))
            else:
                print(Colorate.Horizontal(Colors.yellow_to_red, f"Shared Amount: {TotalSendedShare})"))
                Title(f"Thread :{str(active_count() - 1)} / Hit :{TotalSendedShare} / Fail :{TotalFailedReq}")
        else:
            pass
    except:
        TotalFailedReq  = -1
        Title(f"Thread :{str(active_count() - 1)} / Hit :{TotalSendedShare} / Fail :{TotalFailedReq}")
except:
    pass

I am new to coding and I am just learning to put code together right now. How would I stop this from looping, as it's spamming my command prompt?

This is what it spams btw.

Shared Amount: 553)
Shared Amount: 554)
Shared Amount: 209)
Shared Amount: 211)
Shared Amount: 215)
Shared Amount: 557)
Shared Amount: 219)
Shared Amount: 223)
Shared Amount: 227)
Shared Amount: 231)
Shared Amount: 558)
Shared Amount: 237)
Shared Amount: 239)
Shared Amount: 243)
Shared Amount: 247)
Shared Amount: 251)
Shared Amount: 255)
Shared Amount: 259)
Shared Amount: 263)

What I want it to send is a single Shared Amount: {amount} then the amount its on not a new message each time

CodePudding user response:

In you linked code (that you should include in the question), you have:

        while True:
            Run = True
            while Run:

First of all that is redundant. Secondly it said, "do this thing forever." Change that.

Just as an example of how this control flow can work and not be indefinite:

i = 0
while i < 3:
    print("hi mom")
    i  = 1

You see, this gives it a way to conditionally stop. You can also use while True, but you still need a mechanism to breakout.

while True:
    if lunchtime():
        break
    keep_working()

CodePudding user response:

if int(amount) == 0:
    while True:
        Run = True
        while Run:
            if active_count() <= int(NThread):
                try:
                    Thread(target=SendView, args=(itemID,)).start()
                except:
                    pass
else:

According to the code you sent

you are using tow while True with out using break How exactly do you want the program to end?

However, if you mean that you want to clear the console after each message

You can use the library below

os

Maybe this link will help you

You can also use the following code to clear the console

on windows

import os
os.system("cls")

on linux

import os
os.system("clear")

CodePudding user response:

have you tried demoting the py file loop functions?

  • Related