Author: bugman Date: Mon Aug 8 09:59:06 2011 New Revision: 14246 URL: http://svn.gna.org/viewcvs/relax?rev=14246&view=rev Log: All of the acquire() and release() calls to status.pipe_lock are now within "try ... finally" blocks. This ensures that the lock will be released at the end. Modified: branches/gui_testing/generic_fns/pipes.py Modified: branches/gui_testing/generic_fns/pipes.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/generic_fns/pipes.py?rev=14246&r1=14245&r2=14246&view=diff ============================================================================== --- branches/gui_testing/generic_fns/pipes.py (original) +++ branches/gui_testing/generic_fns/pipes.py Mon Aug 8 09:59:06 2011 @@ -54,18 +54,19 @@ if pipe_to in list(ds.keys()): raise RelaxPipeError(pipe_to) - # Acquire the pipe lock. - status.pipe_lock.acquire() - - # The current data pipe. - if pipe_from == None: - pipe_from = cdp_name() - - # Copy the data. - ds[pipe_to] = ds[pipe_from].__clone__() - - # Release the lock. - status.pipe_lock.release() + # Acquire the pipe lock (data modifying function), and make sure it is finally released. + status.pipe_lock.acquire() + try: + # The current data pipe. + if pipe_from == None: + pipe_from = cdp_name() + + # Copy the data. + ds[pipe_to] = ds[pipe_from].__clone__() + + # Release the lock. + finally: + status.pipe_lock.release() # Notify observers that a pipe change has occurred. status.observers.pipe_alteration.notify() @@ -106,14 +107,15 @@ if pipe_type == 'frame order' and not scipy_module: raise RelaxError("The frame order analysis is not available. Please install the scipy Python package.") - # Acquire the pipe lock. - status.pipe_lock.acquire() - - # Add the data pipe. - ds.add(pipe_name=pipe_name, pipe_type=pipe_type, switch=switch) - - # Release the lock. - status.pipe_lock.release() + # Acquire the pipe lock (data modifying function), and make sure it is finally released. + status.pipe_lock.acquire() + try: + # Add the data pipe. + ds.add(pipe_name=pipe_name, pipe_type=pipe_type, switch=switch) + + # Release the lock. + finally: + status.pipe_lock.release() def cdp_name(): @@ -133,33 +135,34 @@ @type pipe_name: str """ - # Acquire the pipe lock. - status.pipe_lock.acquire() - - # Pipe name is supplied. - if pipe_name != None: - # Test if the data pipe exists. - test(pipe_name) - - # Convert to a list. - pipes = [pipe_name] - - # All pipes. - else: - pipes = ds.keys() - - # Loop over the pipes. - for pipe in pipes: - # Delete the data pipe. - del ds[pipe] - - # Set the current data pipe to None if it is the deleted data pipe. - if ds.current_pipe == pipe: - ds.current_pipe = None - __builtin__.cdp = None - - # Release the lock. - status.pipe_lock.release() + # Acquire the pipe lock (data modifying function), and make sure it is finally released. + status.pipe_lock.acquire() + try: + # Pipe name is supplied. + if pipe_name != None: + # Test if the data pipe exists. + test(pipe_name) + + # Convert to a list. + pipes = [pipe_name] + + # All pipes. + else: + pipes = ds.keys() + + # Loop over the pipes. + for pipe in pipes: + # Delete the data pipe. + del ds[pipe] + + # Set the current data pipe to None if it is the deleted data pipe. + if ds.current_pipe == pipe: + ds.current_pipe = None + __builtin__.cdp = None + + # Release the lock. + finally: + status.pipe_lock.release() # Notify observers that the switch has occurred. status.observers.pipe_alteration.notify() @@ -168,24 +171,25 @@ def display(): """Print the details of all the data pipes.""" - # Acquire the pipe lock. - status.pipe_lock.acquire() - - # Heading. - print(("%-20s%-20s%-20s" % ("Data pipe name", "Data pipe type", "Current"))) - - # Loop over the data pipes. - for pipe_name in ds: - # The current data pipe. - current = '' - if pipe_name == cdp_name(): - current = '*' - - # Print out. - print("%-20s%-20s%-20s" % ("'"+pipe_name+"'", get_type(pipe_name), current)) - - # Release the lock. - status.pipe_lock.release() + # Acquire the pipe lock, and make sure it is finally released. + status.pipe_lock.acquire() + try: + # Heading. + print(("%-20s%-20s%-20s" % ("Data pipe name", "Data pipe type", "Current"))) + + # Loop over the data pipes. + for pipe_name in ds: + # The current data pipe. + current = '' + if pipe_name == cdp_name(): + current = '*' + + # Print out. + print("%-20s%-20s%-20s" % ("'"+pipe_name+"'", get_type(pipe_name), current)) + + # Release the lock. + finally: + status.pipe_lock.release() def get_pipe(name=None): @@ -252,21 +256,22 @@ @rtype: PipeContainer instance or tuple of PipeContainer instance and str if name=True """ - # Acquire the pipe lock. - status.pipe_lock.acquire() - - # Loop over the keys. - for key in list(ds.keys()): - # Return the pipe and name. - if name: - yield ds[key], key - - # Return just the pipe. - else: - yield ds[key] - - # Release the lock. - status.pipe_lock.release() + # Acquire the pipe lock, and make sure it is finally released. + status.pipe_lock.acquire() + try: + # Loop over the keys. + for key in list(ds.keys()): + # Return the pipe and name. + if name: + yield ds[key], key + + # Return just the pipe. + else: + yield ds[key] + + # Release the lock. + finally: + status.pipe_lock.release() def pipe_names(): @@ -286,18 +291,19 @@ @type pipe_name: str """ - # Acquire the pipe lock. - status.pipe_lock.acquire() - - # Test if the data pipe exists. - test(pipe_name) - - # Switch the current data pipe. - ds.current_pipe = pipe_name - __builtin__.cdp = get_pipe() - - # Release the lock. - status.pipe_lock.release() + # Acquire the pipe lock (data modifying function), and make sure it is finally released. + status.pipe_lock.acquire() + try: + # Test if the data pipe exists. + test(pipe_name) + + # Switch the current data pipe. + ds.current_pipe = pipe_name + __builtin__.cdp = get_pipe() + + # Release the lock. + finally: + status.pipe_lock.release() # Notify observers that the switch has occurred. status.observers.pipe_alteration.notify()