~pkgcrosswire/xiphos/main

« back to all changes in this revision

Viewing changes to waffles/nothreads.py

  • Committer: Dmitrijs Ledkovs
  • Date: 2010-11-14 00:38:52 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: dmitrij.ledkov@ubuntu.com-20101114003852-sjt227lz4qqi85xj
New upstream release 3.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# encoding: utf-8
 
3
# Thomas Nagy, 2005-2008 (ita)
 
4
 
 
5
import sys, random, time, traceback, os
 
6
import Build, Utils, Logs, Options
 
7
from Logs import debug, error
 
8
from Constants import *
 
9
 
 
10
class TaskConsumer(object):
 
11
        consumers = 1
 
12
 
 
13
def process(tsk):
 
14
        m = tsk.master
 
15
        if m.stop:
 
16
                m.out.put(tsk)
 
17
                return
 
18
 
 
19
        try:
 
20
                tsk.generator.bld.printout(tsk.display())
 
21
                if tsk.__class__.stat: ret = tsk.__class__.stat(tsk)
 
22
                # actual call to task's run() function
 
23
                else: ret = tsk.call_run()
 
24
        except Exception, e:
 
25
                tsk.err_msg = Utils.ex_stack()
 
26
                tsk.hasrun = EXCEPTION
 
27
 
 
28
                # TODO cleanup
 
29
                m.error_handler(tsk)
 
30
                m.out.put(tsk)
 
31
                return
 
32
 
 
33
        if ret:
 
34
                tsk.err_code = ret
 
35
                tsk.hasrun = CRASHED
 
36
        else:
 
37
                try:
 
38
                        tsk.post_run()
 
39
                except Utils.WafError:
 
40
                        pass
 
41
                except Exception:
 
42
                        tsk.err_msg = Utils.ex_stack()
 
43
                        tsk.hasrun = EXCEPTION
 
44
                else:
 
45
                        tsk.hasrun = SUCCESS
 
46
        if tsk.hasrun != SUCCESS:
 
47
                m.error_handler(tsk)
 
48
 
 
49
        m.out.put(tsk)
 
50
 
 
51
def start(self):
 
52
 
 
53
        while not self.stop:
 
54
 
 
55
                self.refill_task_list()
 
56
 
 
57
                # consider the next task
 
58
                tsk = self.get_next()
 
59
                if not tsk:
 
60
                        if self.count:
 
61
                                # tasks may add new ones after they are run
 
62
                                continue
 
63
                        else:
 
64
                                # no tasks to run, no tasks running, time to exit
 
65
                                break
 
66
 
 
67
                if tsk.hasrun:
 
68
                        # if the task is marked as "run", just skip it
 
69
                        self.processed += 1
 
70
                        self.manager.add_finished(tsk)
 
71
                        continue
 
72
 
 
73
                try:
 
74
                        st = tsk.runnable_status()
 
75
                except Exception, e:
 
76
                        self.processed += 1
 
77
                        if self.stop and not Options.options.keep:
 
78
                                tsk.hasrun = SKIPPED
 
79
                                self.manager.add_finished(tsk)
 
80
                                continue
 
81
                        self.error_handler(tsk)
 
82
                        self.manager.add_finished(tsk)
 
83
                        tsk.hasrun = EXCEPTION
 
84
                        tsk.err_msg = Utils.ex_stack()
 
85
                        continue
 
86
 
 
87
                if st == ASK_LATER:
 
88
                        self.postpone(tsk)
 
89
                elif st == SKIP_ME:
 
90
                        self.processed += 1
 
91
                        tsk.hasrun = SKIPPED
 
92
                        self.manager.add_finished(tsk)
 
93
                else:
 
94
                        # run me: put the task in ready queue
 
95
                        tsk.position = (self.processed, self.total)
 
96
                        self.count += 1
 
97
                        self.processed += 1
 
98
                        tsk.master = self
 
99
 
 
100
                        process(tsk)
 
101
 
 
102
        # self.count represents the tasks that have been made available to the consumer threads
 
103
        # collect all the tasks after an error else the message may be incomplete
 
104
        while self.error and self.count:
 
105
                self.get_out()
 
106
 
 
107
        #print loop
 
108
        assert (self.count == 0 or self.stop)
 
109
 
 
110
 
 
111
# enable nothreads if -j1 is used from the makefile
 
112
if os.environ.get('JOBS') == '1' or sys.platform == 'linux2-hppa':
 
113
        import Runner
 
114
        Runner.Parallel.start = start