×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    May 2008
    Posts
    53

    wierd behaivor with thread

    hello, ive made a simple program that open a socket in a new thread and sends data to a server as a demon.

    im starting the thread when the app begins (t.start()), but misteriously the run function in the thread is executed when i
    exit my app ( if i have t.setDaemon(True) commented) .so, when i exit my app the run function on the thread begins , the app become stucked, but the thread is working and sending data and i cannot close the app and need to take of the battery of the phone for restarting.
    if i uncomment the t.setDaemon(True) the app finish but it never sends data to the server.

    Do anybody know why is happening this wierd behaivor? ive tried the same code in my computer and it works fine? Is this something specific of symbian?
    or pys60? im running pys60 on nokia 1.4.2

    thanks

    oyuky

    Code:
    
    
    import threading
    import httplib
    import urllib
    from socket import *
    
    from math import sqrt
    from graphics import *
    from random import *
    import graphics
    import appuifw
    import e32
    
    
    runnin= 1  
    
    class MiThread(threading.Thread):
        def __init__(self, num):
           
            threading.Thread.__init__(self)
            self.num = num
            self.params = urllib.urlencode({'data': 3453, 'equis': 3123, 'ygri': 12444})
            self.headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
            self.conn = httplib.HTTPConnection("www.ketaplex.net")    
            self.apid = select_access_point()
            self.apo = access_point(self.apid)
            #myip= self.apo.ip()
        def envia(self):
             self.conn.request("POST", "/cgi-bin/grow_recibe.py", self.params, self.headers)
             self.response = self.conn.getresponse()        
                       
           
        def run(self):
            set_default_access_point(self.apo)
            self.s = socket(AF_INET, SOCK_STREAM)
            while runnin == 1:
                   self.envia()
    
    
    BLACK = (0, 0, 0)   
    WHITE = (255, 255, 255)
    GREEN = (255, 0, 255)
    RED = (255, 0, 0)
    coloryo= (255, 255, 0)
    appuifw.app.screen='full'
    appuifw.app.title=unicode('My Test App')
    
    def handle_redraw(rect):   
            if img: canvas.blit(img) 
        
    canvas=appuifw.Canvas(redraw_callback=handle_redraw)
    appuifw.app.body=canvas
    
    
    
    def quit():   
            global running   
            running = False
            conn.close()
            apo.stop()
            
    appuifw.app.exit_key_handler = quit
    
    num_pixels = 100
     
    w, h = canvas.size   
    img = graphics.Image.new((w, h))   
    img.clear(GREEN) 
    
    
    import time
    start_time=time.clock()
    n_frames=0
    
    t = MiThread(0)
    #you need to have setdameon commented for making the thread works when you exit the app
    #t.setDaemon(True)
    
    t.start()
    
    running = True  
    while running:
            img.clear(GREEN)
            img.point(( 100 ,100 ), outline = BLACK, width = 8)
       
            handle_redraw(None)  
            e32.ao_yield()
         
       
            n_frames+=1
    
    
    end_time=time.clock()
    total=end_time-start_time

  2. #2
    Regular Contributor
    Join Date
    May 2008
    Posts
    53

    Re: wierd behaivor with thread

    can anybody try the code please?
    and tell me if you get the same behaivor?


    it seems the main thread of my app or the main app has locked itself and it just unlock when it finish , so maybe thats why the function senddata from my thread begins working when i exit the app.


    any idea?
    maybe there another way of doing this? in python list they recommended to use events instead of threads.

    any hint would be appreciated;

    oyuky

Similar Threads

  1. S60 SDK 3rd edition FP1 Emulator problem
    By justteam in forum Symbian Tools & SDKs
    Replies: 14
    Last Post: 2010-03-23, 08:47
  2. console app running problem
    By xcompass in forum Symbian
    Replies: 3
    Last Post: 2009-05-08, 13:26
  3. error on "Emulator"
    By xmnlk in forum Symbian
    Replies: 3
    Last Post: 2008-05-22, 16:39
  4. Start S60 3rd emulator failure
    By zeusstar in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2006-10-08, 16:55
  5. Link errors when trying to Display bitmap
    By Bkc82 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-16, 22:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×