×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    153

    How to manage time for sub threads

    Hello guys,
    this is a thread question:
    I do've a main thread wich is starting a sub thread at a certain point. The problem: It seems that the sub thread does not get any cpu time to work. If I put
    Code:
    time.sleep(1)
    in the main thread the sub thread is working without complaints.
    But this certainly can't be the way.

    I still have problems to understand the use of active objects (which might be the root of my problem).
    Can somebody give some advice pls?
    e.g. How can I tell the greedy main thread to leave some cpu time for the poor sub thread?
    What can I do with this:
    Code:
    lock = thread.allocate_lock
    lock.release()
    ?

    1000Thx
    novis

  2. #2
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    153

    Re: How to manage time for sub threads

    ok, i'll try to be a little more precise:
    Code:
    import appuifw, e32, time, thread ....
    def subthread():
      download file from a server
    
    thread.start_new_thread(subthread,())
    while running:
         main thread....
         time.sleep(1) # the sub thread will only be executed if I tell the main thread to sleep! 
         e32.ao_yield()
    Why is the subthread only running when I tell the main thread to sleep for a while??

    What can I do to give a certain amount of time to my sub thread??

    THX
    novis

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: How to manage time for sub threads

    hi novis
    i see that the basic answer lies in the concept of active objects only.
    when any one object is running. if u want to start any other object u have to make that object stop for the time being.
    thats the case wid ur code u hav to stop the main thread for allowing the sub thread to do its bit of work.
    plz give a feedback

  4. #4
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    153

    Re: How to manage time for sub threads

    Hi gaba88,
    thx for answering.
    I understand that i need a kind of time sharing between the main and the sub thread. But how can I achieve this?

  5. #5
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    153

    Re: How to manage time for sub threads

    Any suggestions from anyone?

  6. #6
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: How to manage time for sub threads

    Quote Originally Posted by novis View Post
    Any suggestions from anyone?
    Heh, generic answer to generic question: change your app logic from busy loop to event based app. This way your sub thread will get all the time, while main thread is idle waiting for something happen.

    Sorry, but you asked "any suggestions"! Whatever you're trying to do, there are many different ways to do it. Choose what works for you. Are you really, really sure you absolutely need that sub thread?

    Cheers,

    --jouni

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: How to manage time for sub threads

    Quote Originally Posted by novis View Post
    Any suggestions from anyone?
    hi novis sorry for repliyin late
    preferrably Jom is correct that plz have a change in ur programming logic. moreover i m searching some more ideas will reply you soon.
    thanx

  8. #8
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    153

    Re: How to manage time for sub threads

    Hi Guys,
    regarding the event based application structure: You are right JOM, this is a good point, I'll think about it.

    By the way, I found a good website which perfectly explains python threads and there functionality.
    http://linuxgazette.net/107/pai.html
    This site answeres lots of thread questions .
    E.g. very interesting to me was the fact, "that in order to support multi threaded Python programs the interpreter regularly releases and reacquires the lock, by default every 10 bytecode instructions."
    This site also answered my question why my subthread did not get enough cpu time to run (2.1 Locks).

    Cheers
    novis

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: How to manage time for sub threads

    Quote Originally Posted by novis View Post
    Hi Guys,
    regarding the event based application structure: You are right JOM, this is a good point, I'll think about it.

    By the way, I found a good website which perfectly explains python threads and there functionality.
    http://linuxgazette.net/107/pai.html
    This site answeres lots of thread questions .
    E.g. very interesting to me was the fact, "that in order to support multi threaded Python programs the interpreter regularly releases and reacquires the lock, by default every 10 bytecode instructions."
    This site also answered my question why my subthread did not get enough cpu time to run (2.1 Locks).

    Cheers
    novis
    hi novis
    thank you for the link it is really of great help and u r correct that it will answer all the questions related to threads.
    thanx.

Similar Threads

  1. Time is 1 hour off on Nokia 5300
    By Yuriy in forum Mobile Java General
    Replies: 2
    Last Post: 2008-02-24, 21:09
  2. URL do not fire in S60 2nd Ed emulator
    By gigglie in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2008-02-20, 09:43
  3. Time Machine for Symbian Series 60
    By kedarchitale in forum Symbian
    Replies: 2
    Last Post: 2006-03-30, 20:44
  4. 6670 asks for date time on startup
    By collinar in forum General Development Questions
    Replies: 0
    Last Post: 2005-09-28, 16:03
  5. Bizarre calendar/time zone change handling in Nokia 9500
    By noetus in forum General Development Questions
    Replies: 0
    Last Post: 2005-09-19, 19:27

Posting Permissions

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