在子流程中运行Flume shell命令

2024-10-07 00:30:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用subprocess在Pycharm中启动shell命令。我通常从终端启动Flume,但我想在PyCharm中启动它。这是我正在使用的代码:

import subprocess
subprocess.run(["/home/amel/Downloads/flume/bin/flume-ng", "agent", "-n", "TwitterAgent", "--conf-file", "/home/amel/flumeconf", "--conf",
                "/home/amel/flumeconf"])

这就是我得到的:

/home/amel/PycharmProjects/connect-to-mysql/venv/bin/python /home/amel/PycharmProjects/connect-to-mysql/my-connector.py
Info: Including Hive libraries found via () for Hive access
+ exec /usr/lib/jvm/java-11-oracle/bin/java -Xmx20m -cp '/home/amel/flumeconf:/home/amel/Downloads/flume/lib/*:/lib/*' -Djava.library.path= org.apache.flume.node.Application -n TwitterAgent --conf-file /home/amel/flumeconf
log4j:WARN No appenders could be found for logger (org.apache.flume.util.SSLUtil).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Traceback (most recent call last):

当我因为没有收到任何东西而停止运行程序时,我也会得到:

  File "/home/amel/PycharmProjects/connect-to-mysql/my-connector.py", line 2, in <module>
    subprocess.run(["/home/amel/Downloads/flume/bin/flume-ng", "agent", "-n", "TwitterAgent", "--conf-file", "/home/amel/flumeconf", "--conf",
  File "/usr/lib/python3.8/subprocess.py", line 495, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/lib/python3.8/subprocess.py", line 1020, in communicate
    self.wait()
  File "/usr/lib/python3.8/subprocess.py", line 1083, in wait
    return self._wait(timeout=timeout)
  File "/usr/lib/python3.8/subprocess.py", line 1806, in _wait
    (pid, sts) = self._try_wait(0)
  File "/usr/lib/python3.8/subprocess.py", line 1764, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt

Process finished with exit code 130 (interrupted by signal 2: SIGINT)

是否可以使用子进程在PyCharm中运行flume命令? 在这个网站上,它说ApacheFlume确实支持Pythonhttps://towardsdatascience.com/apache-spark-101-3f961c89b8c5


Tags: inpyhomebinlibusrconfline