~ubuntu-branches/ubuntu/trusty/gnome-python/trusty

« back to all changes in this revision

Viewing changes to examples/vfs/cancellation.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-12-02 12:30:09 UTC
  • Revision ID: james.westby@ubuntu.com-20051202123009-z00n5h4uuwfo64ev
Tags: upstream-2.12.2
ImportĀ upstreamĀ versionĀ 2.12.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)