Advertisement
Guest User

Untitled

a guest
Oct 27th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/python
  2. import multiprocessing
  3. import hal
  4. import time
  5.  
  6. def run_process():
  7. ## kind of a silly thing for now, just run sleep
  8. c['program-is-running'] = False
  9. time.sleep(2)
  10. # print("subprocess done sleeping")
  11.  
  12. if __name__ == '__main__':
  13. c = hal.component("execute_process")
  14. c.newpin("exec_activate", hal.HAL_BIT, hal.HAL_IN)
  15. c.newpin("program-is-running", hal.HAL_BIT, hal.HAL_OUT)
  16. c.ready()
  17.  
  18. c['program-is-running'] = True
  19.  
  20. try:
  21. while 1:
  22. c['program-is-running'] = True
  23. # time.sleep(1) is this needed?
  24. input = c['exec_activate']
  25. if input == True:
  26. time.sleep(.2) # debounce
  27. foo = multiprocessing.Process(name='daemon', target=run_process)
  28. foo.start()
  29. # keep checking whether the subprocess is done, doing something each
  30. # time. else you could just wait()
  31. while ( foo.is_alive() ):
  32. # print("foo appears to still be running ...")
  33. # the subprocess has finished...
  34. time.sleep(.01)
  35.  
  36. except KeyboardInterrupt:
  37. raise SystemExit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement