- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有下一个代码:
import kotlin.coroutines.*;
import kotlinx.coroutines.*;
val job = SupervisorJob()
val handler = CoroutineExceptionHandler { _, e ->
println("Catch: $e")
}
val coroutineContext: CoroutineContext = Dispatchers.IO + job + handler
fun main() {
val job1 = GlobalScope.launch(coroutineContext) {
// supervisorScope {
launch {
println("Test0")
for (i in 0..5) {
println("Working! Iteration: $i")
delay(1000)
}
println("Test0 end")
}
launch {
println("Test1")
delay(2000)
throw IllegalAccessException()
}
launch {
println("Test2")
delay(3000)
println("Test2 end")
}
}
//}
runBlocking { job1.join() }
println("Test3")
}
SupervisorJob
通过在
coroutineContext
中传递它进入
GlobalScope.launch
避免在任何地方发生错误时取消任何子级,并且必须在
handler
中处理错误.文档接着说
SupervisorJob
:
Creates a supervisor job object in an active state. Children of a supervisor job can fail independently of each other.
Test0
Working! Iteration: 0
Test1
Test2
Working! Iteration: 1
Catch: java.lang.IllegalAccessException
Working! Iteration: 2
Working! Iteration: 3
Test2 end
Working! Iteration: 4
Working! Iteration: 5
Test0 end
Test3
Test2
Test0
Working! Iteration: 0
Test1
Working! Iteration: 1
Catch: java.lang.IllegalAccessException
Test3
supervisorScope
在上面的代码中。
ViewModel
中设置全局预期行为,例如,为了避免包装每个
launch
在
supervisorScope
?
最佳答案
如 this answer 中所述,您无法更改已启动协程的作业类型。您唯一可以控制的是它的父作业。因为你首先启动一个顶级协程,然后作为它的子进程启动那些你不想影响其他人的失败,最好的选择是你已经发现的,打开一个内部 supervisorScope
.
您无法指定关于给定协程在其子协程失败时的行为方式的全局策略。
关于multithreading - Kotlin Supervisor Job 意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60260589/
我已经使用 Gunicorn + Nginx + Supervisor 部署了一个 Flask 应用程序。它不起作用。在线搜索发现了几个类似问题的报告,但没有一个有适合我们情况的解释或解决问题的修复程
一、简介 Supervisor 是一款 Python 开发的进程管理系统,允许用户监视和控制 Linux 上的进程,能将一个普通命令行进程变为后台守护进程,异常退出时能自动重启 详细介绍查阅:Supe
一, 简介 Dockerfile 运行只支持一条命令,当在Docker里要运行多条命令,用supervisor来管理就比较合适了。 Supervisor是一个 Python 开发的 client
我正在使用 Gunicorn 和 Nginx 与主管一起运行 django 项目。一切正常,但是当我对代码进行一些更改时,主管无法识别它,但它仍然读取旧代码。你能帮我么。我试图重新启动 supervi
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我使用 erlang 作为服务之间的桥梁,我想知道人们对处理断开的连接有什么建议? 我正在从本地文件获取输入并将它们通过管道传输到 AMQP,可以想象 AMQP 代理可能会崩溃。对于这种情况,我想继续
我在哪里可以找到有关如何将动态子进程添加到现有主管的示例( simple_one_for_one 重启策略)? 最佳答案 我做了一些研究,以下是我所拥有的。 首先,这是一个主管的示例回调模块: -mo
我可以为不同的 django-celery 项目使用不同的 supervisor.conf 文件吗? 我在项目本身中为他们两个创建了单独的主管,但主管只与一个一起工作。有什么办法可以分别为它们保存配置
我已经看到了将SupervisorJob传递给CoroutineScope的教程,以避免在子例程之一失败时所有协程作业被取消。 在run3中,我认为将SupervisorJob传递给launch可以获
如何为使用系统上下文创建的两个参与者设置两个不同的主管策略: val exporter = system.actorOf(Props[DataExporter], name = "dataExport
以下是每 2 秒运行 supervisorctl status 的状态预览: [root@docker] ~ # supervisorctl status nginx
编辑:显然脚本确实运行了,但它只是没有启动我的浏览器。仍然不知道为什么。 我正在尝试使用 supervisor 来运行命令/脚本,但我似乎无法让它工作。 我得到了 Pi_Video_looper 的想
我必须运行 laravel 命令 php artisan queue:work --daemon 来运行存储在 Beanstalkd 队列中的作业。 我遇到了两种可能的解决方案: 使用 Supervi
如果我从 apt-get 安装 supervisor 我得到版本 3.0b2-1 如果我运行 sudo service supervisor status 我得到 is running(旧的测试版工作
我正在尝试在主管 (http://supervisord.org/) 的监督下运行流程。 我有两个运行几乎相同环境的环境(Ubuntu 12.04 LTS)。 目前的问题是我尝试在Supervisor
我正在尝试进行自动部署,包括 supervisord 和默认设置路径混淆。 我发现的每个部署方案都使用 /etc/supervisor/supervisor.conf 和 /etc/superviso
Supervisor执行的命令中如何导出环境变量?我第一次尝试: command="export SITE=domain1; python manage.py command" 但主管报告“找不到命令
Docker容器在启动的时候开启单个进程,比如,一个 ssh 或者 apache 的 daemon 服务。 但我们经常需要在一个机器上开启多个服务,这可以有很多方法,最简单的就是把多个启动命令放到
我已经安装并配置了 supervisor。 ps -ax 显示 10 个进程,例如:php/home/vagrant/Sites/mysite/artisan queue:work --tries=1
有人可以解释 Elixir 中的 Supervisor 和 DynamicSupervisor 之间的区别吗? 最佳答案 A DynamicSupervisor is a supervisor des
我是一名优秀的程序员,十分优秀!