File: nothreads.py

package info (click to toggle)
xiphos 4.1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,572 kB
  • sloc: ansic: 25,543; cpp: 13,223; python: 12,684; xml: 2,951; sh: 144; makefile: 42
file content (114 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download | duplicates (5)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2005-2008 (ita)

import sys, random, time, traceback, os
import Build, Utils, Logs, Options
from Logs import debug, error
from Constants import *

class TaskConsumer(object):
	consumers = 1

def process(tsk):
	m = tsk.master
	if m.stop:
		m.out.put(tsk)
		return

	try:
		tsk.generator.bld.printout(tsk.display())
		if tsk.__class__.stat: ret = tsk.__class__.stat(tsk)
		# actual call to task's run() function
		else: ret = tsk.call_run()
	except Exception, e:
		tsk.err_msg = Utils.ex_stack()
		tsk.hasrun = EXCEPTION

		# TODO cleanup
		m.error_handler(tsk)
		m.out.put(tsk)
		return

	if ret:
		tsk.err_code = ret
		tsk.hasrun = CRASHED
	else:
		try:
			tsk.post_run()
		except Utils.WafError:
			pass
		except Exception:
			tsk.err_msg = Utils.ex_stack()
			tsk.hasrun = EXCEPTION
		else:
			tsk.hasrun = SUCCESS
	if tsk.hasrun != SUCCESS:
		m.error_handler(tsk)

	m.out.put(tsk)

def start(self):

	while not self.stop:

		self.refill_task_list()

		# consider the next task
		tsk = self.get_next()
		if not tsk:
			if self.count:
				# tasks may add new ones after they are run
				continue
			else:
				# no tasks to run, no tasks running, time to exit
				break

		if tsk.hasrun:
			# if the task is marked as "run", just skip it
			self.processed += 1
			self.manager.add_finished(tsk)
			continue

		try:
			st = tsk.runnable_status()
		except Exception, e:
			self.processed += 1
			if self.stop and not Options.options.keep:
				tsk.hasrun = SKIPPED
				self.manager.add_finished(tsk)
				continue
			self.error_handler(tsk)
			self.manager.add_finished(tsk)
			tsk.hasrun = EXCEPTION
			tsk.err_msg = Utils.ex_stack()
			continue

		if st == ASK_LATER:
			self.postpone(tsk)
		elif st == SKIP_ME:
			self.processed += 1
			tsk.hasrun = SKIPPED
			self.manager.add_finished(tsk)
		else:
			# run me: put the task in ready queue
			tsk.position = (self.processed, self.total)
			self.count += 1
			self.processed += 1
			tsk.master = self

			process(tsk)

	# self.count represents the tasks that have been made available to the consumer threads
	# collect all the tasks after an error else the message may be incomplete
	while self.error and self.count:
		self.get_out()

	#print loop
	assert (self.count == 0 or self.stop)


# enable nothreads if -j1 is used from the makefile
if os.environ.get('JOBS') == '1' or sys.platform == 'linux2-hppa':
	import Runner
	Runner.Parallel.start = start