Welcome to Dream.In.Code
Getting Help is Easy!

Join 135,912 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,560 people online right now. Registration is fast and FREE... Join Now!




...my sojourn continues

 
Reply to this topicStart new topic

...my sojourn continues, getting the module to send msg

dwun
12 May, 2008 - 10:22 AM
Post #1

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 2

hello...i guess i missed my way somehow and had this posted somewhere else...

"""
thanks for the help nova
i have actually gone thru the docs but i dont seem to understand how to use signals or threading...is there any online doc that u can link me to?...also,i finally came across the sleep() function and it seems to work just fine...
using someething like t=Timer(20,serialOpen()) did not seem to be a wayout for me.
Along the way i got stuck trying to make a function loop forever but cary out certain actions at intervals of time.this is what i've come up with so far:


CODE

def istime2send():

while sendtime()>time():
sleep(sendtime()-time())
print 'sleeping'
while sendtime()==time():
sendtime(0.0011)
print '...'


def sendtime(interval=1):
act_time=3600*interval
sendtime=time()+act_time
return sendtime




help will be highly appreciated
.....attatched is my lil prog so far...



well i got over it somehow by doing this...

CODE

def istime2send(interval=1):
act_time=3600*interval
sendtime=time()+act_time
while sendtime>time():
  sleep(act_time),
  sendtime+=act_time
  return True


it works like a spell!! but...
i still need some more help with selecting numbers,noting that i have to specify the time interval for each and have some way to send it...
i've come up with this so far...

CODE

def send2num():
numz={'08021111111':0.001,'08024434343':0.023,'08776663332':0.1}
for k,v in numz.iteritems():
  if istime2send(v):
   return k #print k



problem is if i use print k,it works properly but if i use return k---which is what i intend to do,it just keeps iteratiing over the first dict item...i.e

CODE

if __name__=='__main__':
while send2num():#or while True
  print send2num()


help will be highly appreciated.



User is offlineProfile CardPM
+Quote Post

linuxunil
RE: ...my Sojourn Continues
19 May, 2008 - 08:07 AM
Post #2

New D.I.C Head
Group Icon

Joined: 7 Mar, 2006
Posts: 46



Thanked: 2 times
Dream Kudos: 125
My Contributions
I would recommend picking up Python Cookbook it has recipes for all of the questions you have.

Here is a recipe from the book about scheduling commands that should work for you. (The book gives permission to use in this manner)

python

import time, os, sys, sched
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
schedule.enter(inc, 0, perform_command, (cmd, inc)) # re-scheduler
os.system(cmd)
def main(cmd, inc=60):
schedule.enter(0,0, perform_command, (cmd, inc)) # 0 == right now
schedule.run()
if __name__ == '__main__':
numargs = len(sys.argv) -1
if numargs < 1 or numargs >2:
print "usage: " + sys.argv[0] + " command [seconds_delay]"
sys.exit(1)
cmd = sys.argv[1]
if numargs < 3:
main(cmd)
else:
inc = int(sys.argv[2])
main(cmd, int)

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:48AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month