mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 07:51:21 +00:00 
			
		
		
		
	target: Replace Target.__copy__ by __getstate__
__getstate__ is also used by the copy module, but allows pickling the class as well. This is useful when using the multiprocessing API, which requires pickling the Target object to send it to the new process.
This commit is contained in:
		
				
					committed by
					
						
						Marc Bonnici
					
				
			
			
				
	
			
			
			
						parent
						
							77f0b1f06d
						
					
				
				
					commit
					a65189f028
				
			@@ -336,13 +336,14 @@ class Target(object):
 | 
			
		||||
        if connect:
 | 
			
		||||
            self.connect()
 | 
			
		||||
 | 
			
		||||
    def __copy__(self):
 | 
			
		||||
        new = self.__class__.__new__(self.__class__)
 | 
			
		||||
        new.__dict__ = self.__dict__.copy()
 | 
			
		||||
        # Avoid sharing the connection instance with the original target, so
 | 
			
		||||
        # that each target can live its own independent life
 | 
			
		||||
        del new.__dict__['_conn']
 | 
			
		||||
        return new
 | 
			
		||||
    def __getstate__(self):
 | 
			
		||||
        return {
 | 
			
		||||
            k: v
 | 
			
		||||
            for k, v in self.__dict__.items()
 | 
			
		||||
            # Avoid sharing the connection instance with the original target,
 | 
			
		||||
            # so that each target can live its own independent life
 | 
			
		||||
            if k != '_conn'
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    # connection and initialization
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user