nothreads.py :  » Build » Waf » waf-1.5.17 » playground » nothreads » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Build » Waf 
Waf » waf 1.5.17 » playground » nothreads » nothreads.py
#!/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':
  import Runner
  Runner.Parallel.start = start

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.