You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/11/11 16:13:55 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #6541: BashOperator does not create temporary shell script

mik-laj commented on a change in pull request #6541: BashOperator does not create temporary shell script
URL: https://github.com/apache/airflow/pull/6541#discussion_r344788134
 
 

 ##########
 File path: airflow/operators/bash_operator.py
 ##########
 @@ -105,42 +105,37 @@ def execute(self, context):
         self.lineage_data = self.bash_command
 
         with TemporaryDirectory(prefix='airflowtmp') as tmp_dir:
-            with NamedTemporaryFile(dir=tmp_dir, prefix=self.task_id) as tmp_file:
-                tmp_file.write(bytes(self.bash_command, 'utf_8'))
-                tmp_file.flush()
-                script_location = os.path.abspath(tmp_file.name)
-                self.log.info('Temporary script location: %s', script_location)
-
-                def pre_exec():
-                    # Restore default signal disposition and invoke setsid
-                    for sig in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
-                        if hasattr(signal, sig):
-                            signal.signal(getattr(signal, sig), signal.SIG_DFL)
-                    os.setsid()
-
-                self.log.info('Running command: %s', self.bash_command)
-                sub_process = Popen(
-                    ['bash', tmp_file.name],
-                    stdout=PIPE,
-                    stderr=STDOUT,
-                    cwd=tmp_dir,
-                    env=env,
-                    preexec_fn=pre_exec)
-
-                self.sub_process = sub_process
-
-                self.log.info('Output:')
-                line = ''
-                for raw_line in iter(sub_process.stdout.readline, b''):
-                    line = raw_line.decode(self.output_encoding).rstrip()
-                    self.log.info(line)
-
-                sub_process.wait()
-
-                self.log.info('Command exited with return code %s', sub_process.returncode)
-
-                if sub_process.returncode:
-                    raise AirflowException('Bash command failed')
+
+            def pre_exec():
+                # Restore default signal disposition and invoke setsid
+                for sig in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
+                    if hasattr(signal, sig):
+                        signal.signal(getattr(signal, sig), signal.SIG_DFL)
+                os.setsid()
+
+            self.log.info('Running command: %s', self.bash_command)
+            sub_process = Popen(
+                ['bash', "-c", self.bash_command],
+                stdout=PIPE,
+                stderr=STDOUT,
+                cwd=tmp_dir,
+                env=env,
+                preexec_fn=pre_exec)
+
+            self.sub_process = sub_process
+
+            self.log.info('Output:')
+            line = ''
+            for raw_line in iter(sub_process.stdout.readline, b''):
+                line = raw_line.decode(self.output_encoding).rstrip()
+                self.log.info("%s", line)
+
+            sub_process.wait()
+
+            self.log.info('Command exited with return code %s', sub_process.returncode)
+
+            if sub_process.returncode != 0:
 
 Review comment:
   I also updated this condition 
   
   > Explicit is better than implicit.
   https://www.python.org/dev/peps/pep-0020/
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services