X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Flink%2FexternAgent.py;h=d3e3af11269d7e1b2d04f05d8ff2bc299fa64290;hb=eac442be1d9b79594f8da14b0340a9d7c037ec92;hp=6112482fac8da3de59d794b200d7bb9e055bbdf0;hpb=4f032479507641dacc772624c4a6b56a664fb249;p=progcomp10.git diff --git a/src/link/externAgent.py b/src/link/externAgent.py index 6112482..d3e3af1 100644 --- a/src/link/externAgent.py +++ b/src/link/externAgent.py @@ -110,13 +110,30 @@ class externAgent (BaseAgent): self.process.stdin.write ( string ) self.process.stdout.readline() # read and discard (should be "OK") + # we kill off the process here because otherwise the class doesn't get + # destroyed until the end of the iteration. This causes us to hold more + # than MAX_TOTAL_AGENTS open for a period of time, which is a bad thing. + if self.IsDead(): + try: + self.process.communicate( "BYE\r\n" ) + except Exception, e: + print "Error in BYE:", self, ":", e + + try: + self.process.kill() + except: + None + + def __del__(self): - try: - self.process.communicate( "BYE\r\n" ) - except Exception, e: - print "Error in BYE:", self, ":", e + #unless we're being deleted unexpectedly, this is a no-op. + if self.process.poll() == None: + try: + self.process.communicate( "BYE\r\n" ) + except Exception, e: + print "Error in BYE:", self, ":", e - try: - self.process.kill() - except: - None \ No newline at end of file + try: + self.process.kill() + except: + None