Note that there are some explanatory texts on larger screens.

plurals
  1. POspinner class thread error - only one thread allowed
    primarykey
    data
    text
    <p>I already asked a question about <a href="https://stackoverflow.com/questions/8315249/implementing-a-spinner-type-object-in-a-class-as-a-subprocess">this</a> 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 <a href="http://pastebin.com/b3cb28BW" rel="nofollow noreferrer">here</a>) but I want to call it multiple times. like this:</p> <pre><code>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...') </code></pre> <p>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.</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload