from garcon import task @task.decorate(timeout=7200) def communicate(activity, pipe, mysql_stderr=None): """Communicate to pipe that there is no more inputs. The pipe will therefore start to read all inputs and write all outputs. Args: activity (ActivityWorker): The swf activity worker. pipe (Popen): Store pipe signal. mysql_stderr (io.TextIOWrapper): Tempfile with stderr of MySQL client subprocess. """ if not pipe: raise Exception('Pipe does not exist') activity.logger.info('Start writing and reading all inputs and outputs') pipe.communicate() # catch exception from MySQL client subprocess, if open tempfile was passed if mysql_stderr: errors = '' mysql_stderr.seek(0) errors_and_warnings = mysql_stderr.readlines() for error_or_warning in errors_and_warnings: # we always get mysql warning about using creds in command line if 'ERROR' in error_or_warning: errors += error_or_warning # catch only errors mysql_stderr.close() if errors: raise Exception(errors) activity.logger.info('All pipe tasks done.')