Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6895307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:53:32+00:00 2026-05-27T06:53:32+00:00

I already asked a question about this yesterday, but now I have another :)

  • 0

I already asked a question about this yesterday, but now I have another πŸ™‚ im trying to write a text effects type class for my terminal apps to use – it does stuff like position cursor, clear screen, colour selection inside the echo string with colours preceded by an ‘@’, random case, colour cylcling and other fun stuff (partly to aid my learning of python and partly for usefulness) – if I wanted to have parts of my class not be a thread how would I do it ? at the moment I have this spinner thing working (whole code here) but I want to call it multiple times. like this:

s=spin()
s.echo('@@') # clears screen
# at the moment - here i get an error because only one thread can be started
s.echo('@red this is red @green green etc...')

the echo function does a lot of stuff as you can see if you look at the pastebin, so i need to call that quite a bit, but multiple calls result in ‘only one thread’ allowed error. perhaps i should be doing it a different way. This was the basic old code before the pastebin stuff.

spinner="β–β–Žβ–β–Œβ–‹β–Šβ–‰β–ˆβ–‰β–Šβ–Œβ–β–Ž" #utf8

#convert the utf8 spinner string to a list
chars=[c.encode("utf-8") for c in unicode(spinner,"utf-8")]

class spin(threading.Thread):

    def __init__(self):
        super(spin,self).__init__()
        self._stop = False

    def run (self):
        pos=0
        while not self._stop:
            sys.stdout.write("\r"+chars[pos])
            sys.stdout.flush()
            time.sleep(.15)
            pos+=1
            pos%=len(chars)

    def cursor_visible(self):
        os.system("tput cvvis")
    def cursor_invisible(self):
        os.system("tput civis")
    def stop(self):
        self._stop = True
    def stopped(self):
        return self._stop == True
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:53:32+00:00Added an answer on May 27, 2026 at 6:53 am

    Only the run method is actually running in a diffrent thread. The problem with your code is that you try to start the thread more than one time (in the echo method). You should check if the thread is already started (look at self._stop) before starting.

    def echo (self, arg=None, sep=' ', end='\n', rndcase=True, txtspeed=0.03, bnum=0, spsw=True):
        print cursave, 
        self.cursor_invisible()
    
        # do you have to do all this ? 
        # c0m4: Only if you need all of those to be accessible for the spin object when echo ends
        self.arg=arg
        self.sep=sep
        self.end=end
        self.rndcase=rndcase
        self.txtspeed=txtspeed
        self.bnum=bnum
        self.spsw=spsw
    
        pos=0
        cmd, txt = [reset], []
        spsw=True
        last_colour=''
        txtpos=0
        if arg:
    
    # test if spinner is wanted and set the text position to be moved across a bit to allow for it
        if spsw is True:
        txtpos=4
        self.start()
    

    The last line if where the troubles start. It is not possible to start a thread more then once. Therefore you need to check if the thread is running before you restart it. Add something like

    self.running = False
    

    to your init method, and then set it in the run method

    self.running = True
    

    Then you can check the status of the object (thread running or not) like this:

    if not self.running:
        self.start()
    

    If you need to run the initial portion of run regardless, you should put that in a separate method, like this:

    def resetThread():
        self.pos = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've already asked this question, but that was about FreeImage . Now I'm trying
I have already asked about this for android, but I will broaden the question
I have already asked a question about this, but the problems keeps on hitting
I am sorry I have already asked this question on Superuser, but nobody answers
I have already asked this question on SuperUser but it was suggested there that
I was about to ask this question...but since it has already asked I will
Yes, I have already asked this question, but the problem is much more specific.
I've already asked this question on several forums, but without any good explanation of
I've seen this question asked already - but none of the answers really gelled
Searching here I found that this question was already asked , but I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.