Changeset 173 in tracdarcs


Ignore:
Timestamp:
05/08/10 21:28:22 (21 months ago)
Author:
lele@…
Hash name:
20100508192822-97f81-b1bb7bbbea66114acc0c79d962bd856ff264cf23
Message:

Optional constraint on the number of concurrent darcs processes
A new option "darcs.max_concurrent_darcses" may set a limit on the
number of concurrent running darcs subprocesses. It is eventually
applied on a per repository basis. By default there are no limits, as
before.

Location:
tracdarcs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tracdarcs/components.py

    r170 r173  
    3737    darcs_command = Option('darcs', 'command', 'darcs', 
    3838                           "Name of the external darcs binary.") 
     39 
     40    max_concurrent_darcses = Option('darcs', 'max_concurrent_darcses', 'false', 
     41                                    "Max number of concurrent darcses running per repository.") 
    3942 
    4043    possible_encodings = Option('darcs', 'possible_encodings', 'utf-8,iso8859-1', 
     
    5659            possible_encodings = [e.strip() 
    5760                                  for e in self.possible_encodings.split(',')] 
     61 
     62        # Setup the semaphore used to limit the number of concurrent running 
     63        # darcs within a single repository. 
     64 
     65        if self.max_concurrent_darcses and int(self.max_concurrent_darcses)>0: 
     66            from command import DarcsCommand 
     67            if DarcsCommand.RUNNING_DARCSES is None: 
     68                from threading import BoundedSemaphore 
     69                DarcsCommand.RUNNING_DARCSES = BoundedSemaphore(value=int(self.max_concurrent_darcses)) 
     70 
    5871        return DarcsRepository(db, dir, self.env.log, darcs, possible_encodings, params) 
    5972 
  • tracdarcs/command.py

    r172 r173  
    4545    ''' 
    4646 
     47    RUNNING_DARCSES = None 
    4748    darcs_version = None 
    4849 
     
    7879        else: 
    7980            command = 'TZ=UTC ' + command 
    80         if self.log: 
    81             self.log.debug(command) 
    82         np = NaivePopen(command, input=input, capturestderr=True) 
     81 
     82        # Respect the maximum number of running darcs limit 
     83        if DarcsCommand.RUNNING_DARCSES is not None: 
     84            if self.log: 
     85                self.log.debug('Asking permission to run %s ...', command) 
     86            DarcsCommand.RUNNING_DARCSES.acquire() 
     87            if self.log: 
     88                self.log.debug('... got permission to run %s', command) 
     89        else: 
     90            if self.log: 
     91                self.log.debug(command) 
     92 
     93        try: 
     94            np = NaivePopen(command, input=input, capturestderr=True) 
     95        finally: 
     96            if DarcsCommand.RUNNING_DARCSES is not None: 
     97                DarcsCommand.RUNNING_DARCSES.release() 
     98 
    8399        if np.errorlevel: 
    84100            err = 'Running (%s) failed: %s, %s: %s' % (command, 
Note: See TracChangeset for help on using the changeset viewer.