File: progress.py

package info (click to toggle)
regina-normal 4.5-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,824 kB
  • ctags: 7,862
  • sloc: cpp: 63,296; ansic: 12,913; sh: 10,556; perl: 3,294; makefile: 947; python: 188
file content (48 lines) | stat: -rw-r--r-- 1,583 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
################################
#
#  Sample Python Script
#
#  Illustrates progress reporting during long operations.
#
#  See the file "progress.session" for the results of running this script.
#
################################

import time

# Create a new triangulation of the lens space L(49,12).
tri = regina.NTriangulation()
tri.insertLayeredLensSpace(49,12)
print tri.getNumberOfTetrahedra(), 'tetrahedra'

# Create a progress manager to use during the lengthy surface enumeration.
# This will be responsible for reporting the state of progress while the
# enumeration runs in the background.
manager = regina.NProgressManager()

# Start the normal surface enumeration.
# Because we are passing a progress manager to enumerate(), the
# enumeration will be started in the background and control will be
# returned immediately to the python console.
surfaces = regina.NNormalSurfaceList.enumerate(tri,
    regina.NNormalSurfaceList.STANDARD, 1, manager)

# Wait for the surface enumeration to fully start up.
while not manager.isStarted():
    time.sleep(1)


# At this point the surface enumeration is now running.
# Output a progress report every second until it's finished.
prog = manager.getProgress()
while not manager.isFinished():
    print 'Progress:', prog.getDescription()
    time.sleep(1)


# The surface enumeration is now complete.
print surfaces.getNumberOfSurfaces(), 'normal surfaces'

# Output the total time spent during the surface enumeration.
print 'Total real time:', prog.getRealTime(), 'seconds'
print 'Total cpu time:', prog.totalCPUTime(), 'seconds'