通过赋值启动子 shell 并等待

2023-12-21

如何通过分配变量来启动一些子shell并等待所有完成?

#!/bin/bash

#some code about $FILE="$1"

cat "$FILE" | while read -r HOST || [[ -n $HOST ]];
do
    echo "$HOST";
    URL="http://$HOST";  QUEST1=$(curl -Is --connect-timeout 200 --max-time 200 "$URL" | head -1);
    P1=$!
    URL="https://$HOST"; QUEST2=$(curl -Is --connect-timeout 200 --max-time 200 "$URL" | head -1);
    P2=$!
    
    echo "$P1 $P2"
    wait $P1 $P2
    R1=$( echo "$QUEST1" | grep -o " 200" );
    R2=$( echo "$QUEST2" | grep -o " 200" );
    echo "$R1 $R2"
    
    if [[ "$R1" || "$R2" ]]; then
    echo "FOUND!";
    fi

done

这是行不通的。echo "$P1 $P2"是空的,因为我在子外壳中。我希望从当代开始,这样我就不必在第一个完成后等待。

好的,这是一个基本问题,但我想了解如何将其应用于其他情况。拜托,我不需要外部文件。

EDIT对于谁不明白。我想把$QUEST1 and $QUEST2在后台加速时间和等待,因为完成后不使用额外的文件。我读了很多,但没有解决任何问题。谢谢


以下是评论的简历:

将子shell输出分配给变量/使用子shell输出(STDOUT)意味着父shell将等待所有子shell子进程的结束,即使有内部有背景的命令。

举个例子 :

x=$( { { /bin/sleep 10 ; echo out1; echo out2; } | head -1; } & ); \
echo "Wrong child PID : $!"

这将阻止父 shell 十秒钟。但是这里你得到了父 shell$!,而不是子 shell 中定义的。为了得到预期的$!,您必须以某种方式将其传输到您的父 shell(通过 STDOUT、STDERR 或文件、或命名管道等)。您可以通过 STDOUT 来实现这一点,例如:

subpid=$( { { { /bin/sleep 10 ; echo out1; echo out2; } | head -1; } 1>&2 & } ; \
echo $!)

在这里,当您的子 shell 将其命令输出发送到 STDERR 并仅输出子 PID 时$!在 STDOUT 上,该命令几乎会立即执行(然后父 shell 不会阻塞 I/O)。

正如您期望尽可能避免 I/O,并且如果您只需要子 shell$!要等待子进程,您可以依赖父 shell 会等待的事实所有 STDOUT 输出来自子外壳。那么你的实际命令就足够了,不需要知道子shell$! :

URL="http://$HOST";  QUEST1=$(curl -Is --connect-timeout 200 --max-time 200 "$URL" \
| head -1);

但是,如果您需要知道子 shell 的子 PID(请注意,该 PID 将是here a 外壳进程号,不是其中之一curl or the head命令)和wait为了让 subshel​​l 命令完成,那么你可以做类似的事情来获得近确定性顺序(如果您的子命令不包含至少一个管道,则该输出将不起作用):

x=$( { spid=$( { { { /bin/sleep 10;echo out1;echo out2; }|head -1;} 1>&2 & };echo $!);} \
2>&1 ; echo "SUBPID=$spid" )

这将屈服x, after 十秒 : SUBPID=<subshell child pid> out1.

此时,这个SUBPID将不再存在(或者不再是“你的”子shell子pid),但你可以记录它或用它做任何你想做的事情。

你的命令将类似于:

URL="http://$HOST";  QUEST1=$( \
{ subpid=$( { { curl -Is --connect-timeout 200 --max-time 200 "$URL" | head -1; \
 } 1>&2 & } ;echo $!); } 2>&1 ; echo "SUBPID=$subpid" );

第一个条目QUEST1应该SUBPID=接下来是curl第一行输出。

为了清楚地表明 shell 会等待,您可以使用 google.com 在内部休眠 10 秒来测试它:

URL="http://www.google.com";  QUEST1=$( { subpid=$( \
{ { { curl -Is --connect-timeout 200 --max-time 200 "$URL"; sleep 10; } | head -1; \
 } 1>&2 & };echo $!); } 2>&1 ; echo "SUBPID=$subpid" );

Update

经过我们的交流,我了解到您正在寻找异步waitable子 shell 中的子进程,您需要在完成时从中获取输出,所有这些不使用临时文件或命名管道.

有一个解决方案不需要临时文件,不需要磁盘写入 I/O,并且基于@hhtamas 创建匿名 fifo 的解决方案 https://superuser.com/questions/184307/bash-create-anonymous-fifo用于匿名管道而不是命名管道。

首先,这是该解决方案的一个简单示例,接下来是针对您的用例的实现(许多curl通过子shell调用)。

解决方案示例:

#!/bin/bash
# We use the bright solution from @htamas to create an anonymous pipe
# in the fds of our current shell.
# see: https://superuser.com/questions/184307/bash-create-anonymous-fifo
#
#
# 1. Creating the anonymous pipe
#

# start a background pipeline with two processes running forever
tail -f /dev/null | tail -f /dev/null &
# save the process ids
PID2=$!
PID1=$(jobs -p %+)
# hijack the pipe's file descriptors using procfs
exec 3>/proc/"${PID1}"/fd/1 4</proc/"${PID2}"/fd/0
# kill the background processes we no longer need
# (using disown suppresses the 'Terminated' message)
disown $PID2
kill "${PID1}" "${PID2}"
# anything we write to fd 3 can be read back from fd 4

#
# 2. Launching an "asynchonous subshell" and get its output
#

# We set a flag to trap the async subshell termination through SIGHUP
ready=0;
trap "ready=1" SIGHUP;

# We launch our subshell for the subprocess "sleep 10" with its output
# connected to the standalone anonymous pipe.
# As the sleep command as no output, we add "starting" and "finish".
# Note that as we send the output elsewhere than STDOUT, it's non blocking
# Note also that we send SIGHUP to our parent shell ($$) when the command finishs.
x=$( { echo "starting"; sleep 10; echo "finish"; echo "EOF"; kill -SIGHUP $$; } >&3 & )

# We now wait that our subshell terminates, it will terminate within the sleep command.
# Will waiting, we can do stuff. Here we just display "Waiting.." every seconds.
while [ "${ready}" = "0" ]; do
   echo "waiting for subshell..";
   sleep 1;
done;

# We close fd 3 early as we should no more output from the subshell
exec 3>&-

# We recover our subshell output from the out point of the autonomous pipe in y
line=""
y=$( while [ "${line}" != "EOF" ] ; do 
      read -r -u 4 line; 
      [ "${line}" != "EOF" ] && echo "${line}"; 
     done );

# And display the output of the subshell
echo "Subshell terminate, its output : ";
echo "${y}"

# close the file descriptors when we are finished (optional)
exec 4<&-

该解决方案需要/proc文件系统,在许多实际的 UNIX 上很常见。解释作为脚本中的注释提供。

小编辑:更好的子 shell 身份进程,等待时更多的进程信息,处理子 shell 的潜在崩溃。

针对您的用例的实施:

#!/bin/bash
#
# Create the anonymous pipe.
# 
# Parameters: None.
# Returns:
#   0 : Success.
#   1 : Failed to launch tails.
#   2 : Failed to exec.
#   3 : Failed to kill tails process.
function CreateAnonymousPipe() {
  # We use the bright solution from @htamas to create an anonymous pipe
  # in the fds of our current shell.
  # see: https://superuser.com/questions/184307/bash-create-anonymous-fifo
  #
  local pid1
  local pid2
  # start a background pipeline with two processes running forever
  tail -f /dev/null | tail -f /dev/null &
  [ $? != 0 ] && return 1;
  # save the process ids
  pid2=$!
  pid1=$(jobs -p %+)
  # hijack the pipe's file descriptors using procfs
  exec 3>/proc/"${pid1}"/fd/1 4</proc/"${pid2}"/fd/0
  [ $? != 0 ] && return 2;
  # kill the background processes we no longer need
  # (using disown suppresses the 'Terminated' message)
  disown "${pid2}"
  kill "${pid1}" "${pid2}"
  [ $? != 0 ] && return 3;

  # anything we write to fd 3 can be read back from fd 4
  return 0;
}
#
# Launch asynchronuously a curl process in a subshell.
# 
# Parameters: { URL } { indice }
#   URL : URL for the curl call.
#   indice : numeric identifier for this call
# Returns:
#   0 : Success.
#   1 : Missing parameters
#   2 : Failed to launch curl subprocess.
#   3 : Failed to access /proc
# STDOUT: PID of the corresponding subshell if success.
function CallCurl() {
  if [ $# != 2 ] ; then
    echo "CallCurl: URL and indice parameter are mandatory." 1>&2
    echo "          CallCurl { URL } { indice }." 1>&2
    return 1;
  fi
  [ ! -d /proc ] && return 3;
  local url="$1"
  local indice="$2"
  local subshell_PID
  # We launch our subshell for the subrprocess curl with its output
  # connected to the standalone anonymous pipe.
  # The curl process output is prefixed with its indice in the URL arrays.
  # Note that the subshell first renames itself with a specific identifier, 
  # curl_<indice>, and that we escape $BASHPID to use its pid for that :
  #   1) We can't use $$ to get the subshell PID as it is not a shell variable that
  #      can be evaluated at execution. As it is "immutable" from the shell point of
  #      view, it'll be always evaluated at first expansion, thus the parent shell PID.
  #   2) We don't rename after subshell launch using $! as its PID, at this time the
  #      subshell could have already terminated and its possible that another process
  #      have since been launched with this PID.
  # Note that we send its output elsewhere than STDOUT (to >&3), so it's non blocking.
  # Note also that we send USR1 signal to our parent shell ($$) when the command finishs.
  subshell_PID=$( { { local my_pid; 
                      eval my_pid="\${BASHPID}";
                      printf 'curl_%s' "${indice}">/proc/"${my_pid}"/comm 2>/dev/null;
                      curl -Is --connect-timeout 200 --max-time 200 "${url}" | head -1 |
                      { read -r line; echo "${indice}: ${line}"; };
                      kill -USR1 $$; 
                    } >&3 & 
                  } ; 
                  echo $!; )
  [ $? != 0 ] && return 2;
  echo "${subshell_PID}"
  return 0;
}
#
# Main URL processor, launch curl subprocess asynchronuously.
# 
# Parameters: { URL ... }
#   URL : URL to call with curl.
# Returns:
#   0 : Success.
#   1 : URL parameter(s) missing
#   2 : Failed to launch curl subprocess.
#   2 : Failed to create anonymous pipe.
# STDOUT: Processing and the outputs of the curl commands
function CurlProcessor() {
  if [ $# = 0 ] ; then
    echo "CurlProcessor: URL parameter is mandatory."  1>&2
    echo "               CurlProcessor { URL ... }." 1>&2
    return 1;
  fi
  local indice=0
  local isalive=0
  local -a URLarray
  # Feed the URL array
  while [ $# -gt 0 ] ; do URLarray+=("$1"); shift; done
  # Initialize a set of flags for each URL
  local -a ready
  for ((indice=0; indice < ${#URLarray[@]}; indice++)) ; do ready+=(0); done
  # Initialize an array of subshell PID for each URL to monitor
  local -a pid
  for ((indice=0; indice < ${#URLarray[@]}; indice++)) ; do pid+=(0); done
  # Initialize an array of subshell output for each URL 
  declare -a output
  for ((indice=0; indice < ${#URLarray[@]}; indice++)) ; do output+=(""); done
  # We create the anonymous pipe
  CreateAnonymousPipe
  [ $? != 0 ] && return 3;
  # Set a trap to catch USR1 and check which subshell are still alive through /proc
  # Local handler for the signals
  function trap_handler() {
    for indice in "${!pid[@]}" ; do
      if [ "${pid[${indice}]}" != "0" ] ; then 
        isalive="$(cat /proc/"${pid[${indice}]}"/comm 2>/dev/null)" 2>/dev/null; 
        [ "${isalive}" != "curl_${indice}" ] && ready[${indice}]=1;
      fi
    done
  }
  trap trap_handler USR1 2>/dev/null;
  # Now launch all the subshell
  for ((indice=0; indice < ${#URLarray[@]}; indice++)) ; do
    pid[${indice}]=$(CallCurl "${URLarray[${indice}]}" "${indice}"); 
    [ $? != 0 ] && return 2;
  done
  # We now wait that our subshells terminate.
  # Will waiting, we can do stuff. Here we just display "Waiting.." every seconds.
  local all_finished=0
  local num_finished=0
  local last_num_finished=0
  local direct_check_timer=0
  while [ "${all_finished}" = "0" ]; do
     # We check each URL subshell flag and loop till there is at least one unfinished.
     all_finished=1
     num_finished=0
     for ((indice=0; indice < ${#ready[@]}; indice++)) ; do 
       if [ ${ready[${indice}]} = 0 ] ; then
         all_finished=0; 
       else
         ((num_finished++));
       fi
     done
     echo "waiting for subshells.. ${num_finished}/${#ready[@]} finished.";
     sleep 1;
     # In case one or more subshell have crashed and thus wont send the USR1 signal, 
     # we launch here the handler to check the states of the subshells after 5sec
     # if there is no subshell termination in the interval.
     if [ "${all_finished}" = "0" ] ; then
       if [ "${last_num_finished}" = "${num_finished}" ] ; then
         ((direct_check_timer++))
         if [ "${direct_check_timer}" = "5" ] ; then
             echo "More than 5 seconds with no progress, doing a direct check."
             direct_check_timer=0 
             trap_handler
         fi
       else
         direct_check_timer=0 
       fi
     fi
     last_num_finished="${num_finished}"
  done;
  # All subshell have finished, we send EOF in the autonaumous pipe
  echo "EOF" >&3
  # We close fd 3 early 
  exec 3>&-
  # We recover our subshells outputs from the out point of the autonomous pipe
  local line=""
  local control=""
  while [ "${line}" != "EOF" ] ; do 
    read -r -u 4 line; 
    if [ "${line}" != "EOF" ] ; then
      # Each line should have "indice: " as a prefix to identify the URL associated
      indice="${line/: */}"
      if [ "${indice}" ] ; then
        control="${indice/[0-9]*/}"
        if [ "${control}" = "" ] ; then
          if [ "${output[${indice}]}" != "" ] ; then
            output[${indice}]="${output[${indice}]}\n${line/[0-9]*: /}"
          else
            output[${indice}]="${line/[0-9]*: /}"
          fi
        fi
      fi
    fi
  done
  # close the file descriptors when we are finished (optional)
  exec 4<&-
  # And display the output of the subshells
  echo "Subshells have all terminated, the output : ";
  for ((indice=0; indice < ${#URLarray[@]}; indice++)) ; do 
    echo "Output from URL ${URLarray[${indice}]} :"
    echo "${output[${indice}]}"
  done
  return 0;
}
#
# An example call of CurlProcessor
#
CurlProcessor "http://www.google.com" "http://stackoverflow.com/" "http://en.cppreference.com/"

通过示例调用,您将获得以下输出:



waiting for subshells.. 0/3 finished.
waiting for subshells.. 3/3 finished.
Subshells have all terminated, the output :
Output from URL http://www.google.com :
HTTP/1.1 200 OK
Output from URL http://stackoverflow.com/ :
HTTP/1.1 301 Moved Permanently
Output from URL http://en.cppreference.com/ :
HTTP/1.1 302 Found
  

什么时候很快就下来了 https://downdetector.com/status/fastly/news/392592-problems-at-fastly/, 你会得到 :



waiting for subshells.. 0/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
More than 5 seconds with no progress, doing a direct check.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
More than 5 seconds with no progress, doing a direct check.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
waiting for subshells.. 2/3 finished.
More than 5 seconds with no progress, doing a direct check.
waiting for subshells.. 3/3 finished.
Subshells have all terminated, the output :
Output from URL http://www.google.com :
HTTP/1.1 200 OK
Output from URL http://stackoverflow.com/ :
HTTP/1.1 503 Backend unavailable, connection timeout
Output from URL http://en.cppreference.com/ :
HTTP/1.1 302 Found
  

(测试脚本的最佳时机^^。)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过赋值启动子 shell 并等待 的相关文章

  • PHP exec rm -Rf 不适用于子目录

    我试图删除特定文件夹中的所有内容 但它似乎不会影响子文件夹 但它应该 因为 bash 命令是从控制台执行的 system rm Rf some dir 该命令中不需要星号 如果要与文件一起删除目录 请同时删除斜杠 留下斜杠将删除文件 但保留
  • adb shell 输入带有空格的文本

    如何发送带有空格的文本 例如 一些文字 using adb shell input text 找到以下解决方案 adb shell input text some stext 工作正常 但是有什么简单的方法可以用 s 替换空格吗 Examp
  • 不要将变量内容视为 sed 中的特殊字符

    我有以下内容sed命令 sed i 4i CHANGES CHANGELOG rst 然而 我的 CHANGES变量看起来像这样 title list elem elem 因此 上述命令失败并出现以下错误 sed e expression
  • Grep 递归和计数

    需要在具有大量子目录的目录中搜索文件内的字符串 我在用着 grep c r string here 我怎样才能找到总数量 如何仅输出至少具有一个实例的文件 使用 Bash 的进程替换 这给出了我认为是您想要的输出 如果不是 请澄清问题 gr
  • 带有二进制数据的 Bash echo 命令?

    有人可以解释一下为什么这个脚本有时只返回十六进制字符串表示形式的 15 个字节吗 for i in 1 10 do API IV openssl rand 16 API IV HEX echo n API IV od vt x1 w16 a
  • wget 并行下载文件并重命名

    我有一个包含两列的文本文件 第一列是要保存的名称 第二列是资源的 url 地址 10000899567110806314 jpg http lifestyle inquirer net files 2018 07 t0724cheekee
  • 使用 IFS bash 进行 CSV 解析:选择“;”作为分隔符

    我有一个包含 130 列的 CSV 我需要用它来做 3 个 csv 我用 while 和 IFS 循环 因为我需要对每一行的变量进行一些处理 这是我所做的 while IFS read my 130 vars what i do with
  • 在cmake中集成bash测试脚本

    我有一个 C cmake 项目 它使用 Boost Test 进行单元测试 现在我想向 cmake 公开一系列 bash 脚本 用于集成测试 假设每个脚本在以下情况下返回 0PASS或某些情况下 0FAILURE 我希望每次运行时都执行每个
  • 从命令行更改 konsole 选项卡标题并使其持久?

    如何更改 konsole 选项卡标题 默认情况下 它设置为 u n 所以它总是自动改变 我可以这样设置 qdbus org kde konsole KONSOLE DBUS SESSION setTitle 1 My Title 但是一旦您
  • Bash 的源命令无法处理从互联网上卷曲的文件

    我正在尝试使用curl从互联网获取脚本文件 如下所示 source lt curl url echo done 我看到的是 完成 得到了回响before卷曲甚至开始下载文件 这是实际的命令和输出 bash 3 2 source lt cur
  • “alias: =: not found”,且未定义别名,在 .bashrc 中使用“alias ll = 'ls -l'”

    我在 Mac OSX 上并尝试在 bashrc 中添加一些基本别名 例如alias ll ls l 我在 bash profile 中获取了 bashrc 启动时它识别出我在 bashrc 中的函数 但是 每次添加别名然后尝试启动它时 我都
  • sed 和 rev shell 命令转换为 Python 脚本 [重复]

    这个问题在这里已经有答案了 有一个shell命令 我正在尝试将逻辑转换为python 但我不知道该怎么办 我需要一些帮助 shell命令是这样的 cd tests src main test ls find name vrlp while
  • 命令中的 Bash 变量扩展[重复]

    这个问题在这里已经有答案了 DATE 1 week ago date date DATE 不起作用 我怎样才能让它发挥作用 我可以做 DATE CMD date date DATE eval DATE CMD 但我不想将整个命令存储在变量中
  • 批量检测系统是32位还是64位

    有谁知道如何创建一个批处理文件 如果是 64 位系统 可以对一个程序进行 shell 处理 如果是 32 位系统 则可以对另一个程序进行 shell 处理 检查 PROCESSOR ARCHITECTURE being x86 if PRO
  • 是否可以从应用程序执行 ADB shell 命令?

    我有一个安卓电脑 http www timingpower com rk3288 with root 开箱即用 连接到始终以横向显示的外部显示器 HDMI 和 USB 即使我的应用程序在清单中的活动声明中指定纵向 android scree
  • 将 apache documentRoot 设置为符号链接(以便于部署)

    我们正在寻找一种将 Apache DocumentRoot 指向符号链接的方法 例如 文档根目录 var www html finalbuild Finalbuild 应该指向 home user build3 之类的文件夹 当我们将新构建
  • Bash 目录上的 For 循环

    快速背景 ls src file1 file2 dir1 dir2 dir3 Script bin bash for i in src do if d i then echo i fi done Output src dir1 src di
  • 使用转义序列渲染文本(如终端)

    你好 我正在寻找一些库或工具来在文本文件中呈现带有转义序列字符的文本 我不知道如何称呼它 但这是一个例子 echo e abc vdef abc def echo e abc vdef gt tmp xxxxx vi tmp xxxxx 我
  • Shell 执行:时间与 /usr/bin/time

    当 bash zsh 执行以下操作时会发生什么 usr bin time l sleep 1 1 00 real 0 00 user 0 00 sys 516096 maximum resident set size 0 average s
  • LaunchAgent 不运行 shell 脚本

    在 Catalina 之前的 macOS 下 我有一个每天运行 shell 脚本的 LaunchAgent 升级并切换到 zsh 后 它不起作用 我检查过的事情 shebang 切换到 zsh shell脚本可以从命令行手动执行 sh 在系

随机推荐

  • 诗歌配置无效 - 不允许附加属性(“组”是意外的)

    最近 我在诗歌方面遇到了这个问题 我所有使用诗歌的命令都失败并出现以下错误 RuntimeError The Poetry configuration is invalid Additional properties are not all
  • 如何从 torrent 跟踪器响应中获取对等列表

    我正在制作一个种子客户端 我解码 torrent 文件并将此请求发送到跟踪器 http tracker mininova org announce uploaded 0 downloaded 0 compact 0 event starte
  • 为什么函数式语言如此大量地使用列表?

    我的意思是 列表相对于其他数据结构有哪些优势 使其在函数式语言中几乎不可避免 没有勺子 如果我告诉你没有字符串这样的东西怎么办 仅存在单个字符的列表 那么如果我告诉你不存在列表这样的东西呢 仅存在对 construct a pair of
  • Visual Studio Code 无法在 WSL 2 上运行/工作

    不知怎的 当我跑步时code 在 WSL 内部 它根本不执行任何操作 如果我which code它确实返回了 Windows 上的 VS Code 路径 但仍然没有任何反应 经过一番研究 真正解决我问题的是 在 WSL 终端中 运行rm r
  • 用于返回合格子节点值的字符串串联的 XPath

    任何人都可以建议一种 XPath 表达式格式 该格式返回一个字符串值 其中包含元素的某些合格子节点的串联值 但忽略其他值 div This text node should be returned em And the value of t
  • UIGestureRecognizer 导致循环保留?

    我在想 如果你将目标指定为self在手势识别器中initWithTarget action 方法 会引起循环retain吗 自从self将保留识别器self gestureRecognizers并且手势识别器也有可能将自身保留在initWi
  • 在类方法中使用 self

    我在 ShareKit 中遇到了这段代码 我不明白作者的想法 使用self在类方法中 有警告 不兼容的指针类型将 Class 发送到参数类型id
  • 用户在权限屏幕上单击“允许”后启动活动

    我的一项活动需要位置许可 我编写了下面的代码来获得许可 但在这种情况下 如果应用程序最初没有位置权限 则用户需要单击两次才能打开活动 我可以进行一些更改 以便一旦用户在 权限 屏幕上单击 允许 只有然后意图才会触发 int PERMISSI
  • 我无法将信息从表单输入到数据库[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 询问代码的问题必须对所解决的问题表现出最低限度的了解 包括尝试的解决方案 为什么它们不起作用以及预期结果 也可以看看 Stack Over
  • 如何检查 keras 训练是否已经在 GPU 中运行?

    有时我会犯一个错误 尝试在同一个 GPU 两个不同的脚本 中使用 keras 同时运行两个训练 导致我的机器崩溃或破坏两个训练 我希望能够在我的脚本中测试是否有一些训练正在运行 因此可以更改 GPU 或停止新的训练 我发现寻找答案的唯一提示
  • 无法在 vba IE 中应用正则表达式

    我使用vba结合IE编写了一个脚本来解析应用程序网页中的联系信息regex在上面 我进行了很多搜索 但找不到任何可以满足我的要求的示例 这pattern可能并不理想地找到phone号 但这里主要关心的是我如何使用pattern在 vba I
  • 在 C# 中解析原始 Protocol Buffer 字节流

    给定一个协议缓冲区编码Stream or byte 但不知道对象类型本身 我们如何打印消息的骨架 该用例用于调试基于 protobuf 的 IO 以进行根本原因分析 如果有现有的工具可以从二进制文件中解析原始 Protocol Buffer
  • 如何滚动到英国底部?

    我使用 PhoneGap 开发了一款应用程序 在我的应用程序中 我使用在列表视图中显示了许多元素ui li 这里我想滚动到列表中的最后一个元素 为此 我使用了以下代码 dates li last addClass active li foc
  • ScriptManager.RegisterClientScriptIninclude 在 UpdatePanel 中不起作用

    我已浏览网络 但尚未找到以下问题的解决方案 我有这个示例页面 ScriptManager aspx ScriptManager an UpdatePanel a MultiView有两个Views和两个LinkButtons两个视图之间切换
  • 如何在build.gradle中指定Android应用程序支持的架构?

    我的Android应用程序仅支持arm64 v8a和armeabi v7a 但是 由于依赖项之一 我在 apk 的 lib 文件夹中看到以下内容 arm64 v8a armeabi armeabi v7a mips x86 x86 64 这
  • NSURLSession用于网络图片下载+缓存

    有许多第三方库用于加载网络图像 然后将其存储到磁盘和 或内存中 然而它是好简单使用简单的 NSURLSession API 调用来实现它 这是代码 NSURLCache myCache NSURLCache alloc initWithMe
  • Haskell 中如何实现列表推导式?

    列表推导式只是一种语言功能吗 使用纯 Haskell 伪造列表理解的最简单方法是什么 你必须使用 do 块 gt gt 来做到这一点或者你可以使用其他一些 将列表理解结合在一起的方法 澄清 伪造 列表理解是指创建一个接受相同输入并产生相同输
  • 服务器日志在 POST 请求之前显示 GET 请求

    当我查看服务器日志时 我看到定期 GET 请求在来自同一 IP 具有相同引荐来源网址的 POST 请求之前立即传入 我期望的是 POST 但不是 GET 有没有人见过这个 我正在使用 javascript 在 iframe 内动态创建一个表
  • ConvertTo-Csv 输出不带引号

    我在用ConvertTo Csv获取逗号分隔的输出 get process convertto csv NoTypeInformation Delimiter 它的输出如下 NounName Name Handles VM WS 但是我想获
  • 通过赋值启动子 shell 并等待

    如何通过分配变量来启动一些子shell并等待所有完成 bin bash some code about FILE 1 cat FILE while read r HOST n HOST do echo HOST URL http HOST