You Are Here:

Community: Developer Discussion Boards

#1 Old Sched module problem... - 2005-09-03, 19:39

Join Date: Sep 2005
Posts: 13
tonino12345
Offline
Registered User
Hi, i'm italian so i'm sorry for my bad english.
I'm developing an application that every 30 sec call the location function to discover the cell ID. I try to import the sched module but it's no insert in python series 60. Do exist an alternative solution at this problem?
I'm considering to use Active Object importing e32 module, but i've got some difficulties...
Can you help me with an example.
Lots of thanks
Reply With Quote

#2 Old Re: Sched module problem... - 2005-09-04, 23:36

Join Date: Sep 2003
Posts: 9
skunkah
Offline
Registered User
You could use ao_sleep() for this. If you want to schedule your function in 30 seconds you could use ao_sleep() like: ao_sleep(30,self.function_name)

This will immediatly return and call the function with function_name 30 seconds later in the current thread.
Reply With Quote

#3 Old Re: Sched module problem... - 2005-09-05, 18:25

Join Date: Sep 2005
Posts: 13
tonino12345
Offline
Registered User
Lots of thanks!
I'll try with this solution...
Reply With Quote

#4 Old Re: Sched module problem... - 2005-09-11, 12:36

Join Date: Sep 2005
Posts: 13
tonino12345
Offline
Registered User
Hi skunkah, I've yet some problems to develop my application. In particular way, I would code a listener that alert me when the cellID changes. Can you help me?
Reply With Quote

#5 Old Re: Sched module problem... - 2007-10-15, 15:22

Join Date: May 2006
Posts: 2
diegodobelo
Offline
Registered User
you can try to create a function than watch to changes frequently and notify them:

def notify():
#Look for changes here
ao_sleep(0.1,notify)
Reply With Quote

#6 Old Re: Sched module problem... - 2007-10-15, 20:44

Join Date: Jun 2005
Posts: 382
y.a.k
Offline
Regular Contributor
Quote:
Originally Posted by skunkah View Post
You could use ao_sleep() for this. If you want to schedule your function in 30 seconds you could use ao_sleep() like: ao_sleep(30,self.function_name)

This will immediatly return and call the function with function_name 30 seconds later in the current thread.
The problem with ao_sleep() is that if you quit the app while it is sleeping, the app will "crash".

He should use e32.Ao_timer() instead.

Code:
timer = e32.Ao_timer()
timer.after(30, my_function)

(...)

# this has to be called if the app is going to quit
timer.cancel()
cancel() can be called at any time to stop the timer. If the timer is already stopped, cancel() does nothing. A timer can be restarted but it has to be stopped first. If you want a cyclic timer that will fire every 30 seconds (for example), you have to call the after() each time in the my_function() function.
Reply With Quote

#7 Old Re: Sched module problem... - 2007-10-16, 13:20

Join Date: May 2007
Posts: 2,737
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by tonino12345 View Post
Hi, i'm italian so i'm sorry for my bad english.
I'm developing an application that every 30 sec call the location function to discover the cell ID. I try to import the sched module but it's no insert in python series 60. Do exist an alternative solution at this problem?
I'm considering to use Active Object importing e32 module, but i've got some difficulties...
Can you help me with an example.
Lots of thanks
Hello tonino12345
I would recommend the following code:

Code:
import location,e32

def call()
    mcc, mnc, lac, cellid = location.gsm_location()
    print cellid
# loop forever
while True:
     e32.ao_sleep(30)
     call()
And in case you want a notification you can use a note or play a sound using the audio module in the call function itself...

Hope that helps
Reply With Quote

#8 Old Re: Sched module problem... - 2007-10-16, 15:42

Join Date: Oct 2007
Posts: 67
nlsp
Offline
Regular Contributor
Quote:
Originally Posted by croozeus View Post
Hello tonino12345
I would recommend the following code:

Code:
import location,e32

def call()
    mcc, mnc, lac, cellid = location.gsm_location()
    print cellid
# loop forever
while True:
     e32.ao_sleep(30)
     call()
And in case you want a notification you can use a note or play a sound using the audio module in the call function itself...

Hope that helps
As y.a.k. stated below, Ao_timer should be used in favour of ao_sleep, and the above would be coded like:

Code:
import e32
import location
class Scheduler(object):
  sleeptime = 30
  def __init__(self):
    self._timer = e32.Ao_timer()
    self.start_timer()
  def start_timer(self):
    self._timer.after(self.sleeptime, self.handler)
  def __del__(self):
    self._timer.cancel()
  def handler(self):
    self.start_timer()
    mcc, mnc, lac, cellid = location.gsm_location()
    print cellid

scheduler = Scheduler()
Now when scheduler gets deleted at interpreter exit time, the timer is cancelled and no crash occurs.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
problem when stop playing video on 3650 and try to play again niko86 Mobile Java General 5 2007-08-03 08:40
netcards - Problem with opening adapter kernj Symbian Tools & SDKs 5 2007-01-10 09:56
Nokia 12i module - SIM cards problem knapczyk Nokia M2M 1 2005-03-29 16:46
Problem: S60 SDK for CW in PC with .NET anttij Carbide.c++ IDE and plug-ins 1 2005-02-28 12:36
wireless problem sash_mca General Browsing 0 2003-06-06 12:34

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia