Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python threads and queue

Name: Anonymous 2010-11-03 19:33

Hey /prog/ why is my program broke?
info on graphics.py
http://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html


from graphics import *
import queue
import random
import threading
import gc


WINDOW_SIZE = 500
NUMBER_OF_STARS = 100
iYModify = 0
iXModify = 0
iSpeed = []
oRespawnQ = queue.Queue()
oElminationQ = queue.Queue()
iX = 0
iY = 0
oStarSpeck = [Point(0, 0) for _ in range(NUMBER_OF_STARS)]
oSelectStar = Point(0,0)

def main():

    #Draw the window and paint it black
    formMain = GraphWin("stars", WINDOW_SIZE, WINDOW_SIZE)
    formMain.setBackground("black")
    #Draw crosshairs in the background
    threading.Thread(target=drawCrossHair(formMain)).start()
    #formMain.
    #Put the initial stars up on the screen
    for iStarIndex in range(NUMBER_OF_STARS):
        iSpeed.append(random.randint(1, 25))
        oStarSpeck[iStarIndex] = drawStar(oStarSpeck[iStarIndex], formMain)
       
    while (0 == 0):
        #Randomly select a star to work with
        iStarIndex = random.randint(0, NUMBER_OF_STARS - 1)
        oSelectStar = oStarSpeck[iStarIndex]
        iX = int(oSelectStar.getX())   
        iY = int(oSelectStar.getY())
        #Move selected star outwards according to it's speed variable
        if iX > (WINDOW_SIZE/2): iXModify = (iSpeed[iStarIndex])
        else: iXModify = -(iSpeed[iStarIndex])
        if iY > (WINDOW_SIZE/2): iYModify = (iSpeed[iStarIndex])
        else: iYModify = -(iSpeed[iStarIndex])
       
        oSelectStar.move(iXModify, iYModify)
       
        if (iX > WINDOW_SIZE) | (iY > WINDOW_SIZE) | (iY < 0) | (iX < 0) :
            ### A THREAD IS CREATED HERE
            ### A THREAD IS CREATED HERE
            ### A THREAD IS CREATED HERE
            tdDrawStar = threading.Thread(target = drawStar, arg = oElminationQ, oRespawnQ, formMain)
           
            #oStarSpeck[iStarIndex] = drawStar(oStarSpeck[iStarIndex], formMain)
            if (oRespawnQ.empty() != 1): oStarSpeck[iStarIndex] = oRespawnQ.get()
        gc.collect()
            
           

       
def drawStar(oIncomingQ, oOutgoingQ, oForm):       
    while (0==0):
        while (oIncomingQ.empty() != 1):
            oStarSpeck = Point(random.randint(1, WINDOW_SIZE), random.randint(1,WINDOW_SIZE))
   
            if (random.randint(1,2)    > 1): oStarSpeck.setFill("white")
            elif (random.randint(1,3)  > 1): oStarSpeck.setFill("gray")
            elif (random.randint(1,10) > 1): oStarSpeck.setFill("orange")
            elif (random.randint(1,3)  > 1): oStarSpeck.setFill("red")
            else:                            oStarSpeck.setFill("blue")
            oStarSpeck.draw(oForm)
            oOutgoingQ.put(oStarSpeck)
   
       
def drawCrossHair(oForm):
    oCallibrate = Point(WINDOW_SIZE/2, WINDOW_SIZE/2)
    oCallibrate.setFill("cyan")
    oCallibrate.draw(oForm)
   
    oCrossHair1 = Line(Point(WINDOW_SIZE/2 + 10, WINDOW_SIZE/2 +10 ), Point(WINDOW_SIZE/2 +10 , WINDOW_SIZE/2 - 10))
    oCrossHair1.setFill("red")
    oCrossHair2 = Line(Point(WINDOW_SIZE/2 - 10, WINDOW_SIZE/2 -10 ), Point(WINDOW_SIZE/2 -10 , WINDOW_SIZE/2 + 10))
    oCrossHair2.setFill("red")
    #oCrossHair2.setArrow("both")
   
    oCrossHair3 = Line(Point(WINDOW_SIZE/2  , WINDOW_SIZE/2 -1 ), Point(WINDOW_SIZE/2 -1 , WINDOW_SIZE/2 -1 ))
    oCrossHair3.setFill("red")
    oCrossHair3.setArrow("both")
    oCrossHair3.draw(oForm)
   
    oCrossHair3 = Line(Point(WINDOW_SIZE/2   , WINDOW_SIZE/2 +1 ), Point(WINDOW_SIZE/2 +1 , WINDOW_SIZE/2 +1 ))
    oCrossHair3.setFill("red")
    oCrossHair3.setArrow("both")
    oCrossHair3.draw(oForm)
   
    oCrossHair1.draw(oForm)
    oCrossHair2.draw(oForm)

def getRelPos(oForm):
    oForm.checkMouse()              
              
 #   formMain.getMouse()
   
main()

Name: Anonymous 2010-11-03 20:06

K guys I got it working as much as it should work so disregard my last.
>>6
I dunno I've never used garbage collection and have no idea how it works, this program leaks memory all over though and inserting that line seemed to slow that growth at least some. 

I keep making point objects I have the feeling that they're not going away when I'm done with them.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List