home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-gnome2 / examples / vfs / cancellation.py < prev    next >
Encoding:
Python Source  |  2005-05-15  |  685 b   |  30 lines

  1. #! /usr/bin/env python
  2. import time
  3. import gnomevfs
  4. import thread
  5. import sys
  6.  
  7. context = gnomevfs.Context()
  8.  
  9. def do_something(context):
  10.     print 'Running counter in thread %s' % thread.get_ident()
  11.     c = 0
  12.     while True:
  13.         time.sleep(0.1)
  14.         c += 1
  15.         print c
  16.         if context.check_cancellation():
  17.             print 'Cancelled counter'
  18.             break
  19.  
  20. def cancel_in_thread(context):
  21.     print 'Calling cancel in thread %s' % thread.get_ident()
  22.     context.cancel()
  23.  
  24. if __name__ == '__main__':
  25.     thread.start_new_thread(do_something, (context,))
  26.     thread.start_new_thread(cancel_in_thread, (context,))
  27.     time.sleep(1)
  28.     context.cancel()
  29.     time.sleep(1)
  30.