小编Geo*_*zos的帖子

如何在Dart中测试函数的存在?

有没有办法在Dart中测试函数或方法的存在而不试图调用它并捕获NoSuchMethodError错误?我正在寻找类似的东西

if (exists("func_name")){...}
Run Code Online (Sandbox Code Playgroud)

测试名为的函数是否func_name存在.提前致谢!

dart dart-mirrors

7
推荐指数
1
解决办法
937
查看次数

如何用&(用bash)制作进程并杀死它们?

我有一个脚本,在后台启动另一个脚本,然后终止它.我期待儿童脚本消失,但最终仍然设法打印一些输出.这是一个例子:

在脚本one.sh:

echo "this is one"
./two.sh &
sleep 1
pid=$!
kill $pid
echo "this was one"
Run Code Online (Sandbox Code Playgroud)

在脚本two.sh:

echo "this is two"
./three.sh
echo "this was two"
Run Code Online (Sandbox Code Playgroud)

在脚本three.sh:

echo "this is three"
sleep 5
echo "this was three"
Run Code Online (Sandbox Code Playgroud)

我跑了./one.sh,它应该在后台运行two.sh,然后运行three.sh但不在后台运行!得到的输出是:

this is one
this is two
this is three
this was one
this was three
Run Code Online (Sandbox Code Playgroud)

不应该在输出中出现"this is three",因为three.sh没有在后台运行而two.sh被one.sh终止了?您是否也可以向我指出任何文档,这些文档描述了进程在后台(而非)在后台运行时的行为以及终止时会发生什么?

非常感谢您的帮助!

bash process

7
推荐指数
1
解决办法
3742
查看次数

在Python中阻止dict?

Python中的数据结构是否类似于阻塞字典?此数据结构必须满足以下要求:

  • 它必须是随机可访问的,并允许修改/删除任何元素(不只是第一个或最后一个)
  • 它必须有一个阻塞get()和put()
  • 它必须是线程安全的

我会使用一个队列,但是,虽然阻塞和线程安全,但它不是随机可访问的.dict也没有阻塞(就我的Python知识而言).例如,考虑一个生产者线程将键 - 值对添加到这样的数据结构(如果已经存在,则更新现有键的值 - 这是队列不会将其删除的位置),以及阻止get()的工作者并在这些键值对可用时使用它们.非常感谢!

编辑:让我们假设生产者轮询CI服​​务器并获得项目状态对.它生成项目状态的差异,并将它们放在上述数据结构中.工作人员获取这些项目状态更新,并在屏幕上逐个显示它们作为动画.

class Producer:
  def generateProjectStatusChanges():
    ...
  def updateSuperAwesomeDataStructure(changes):
    for (proj, stat) in changes:
      #queue won't do cause the update could take place in the middle of the queue
      #hence the dict behavior
      superAwesomeDS.putOrUpdate(proj, stat) 
  def watchForUpdates():
     changes = generateProjectStatusChanges()
     updateSuperAwesomeDataStructure(changes)
     time.sleep(self.interval)

class Worker:
  def blockingNotifyAnimation():
    ...
  def watchForUpdates():
    while true:
      proj, stat = superAwesomeDS.getFirstPair() #or any pair really
      blockingNotifyAnimation(proj, stat)
Run Code Online (Sandbox Code Playgroud)

python multithreading dictionary

5
推荐指数
1
解决办法
745
查看次数

Prolog中的字符串流?

我必须使用一些 SWI-Prolog 代码来打开一个新流(它在文件系统上创建一个文件)并倒入一些数据。生成的文件稍后在代码中的其他地方读取。

我想用 Prolog 中的字符串流替换文件流,以便不创建文件,然后将放入流中的所有内容作为一个大字符串读取。

SWI-Prolog 有字符串流吗?如果是这样,我如何使用它们来完成此任务?如果您能提供一个小片段,我将不胜感激。谢谢!

stream stringstream swi-prolog

4
推荐指数
1
解决办法
1276
查看次数