- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Swift 4 中,在 Xcode 版本 9.3.1 (9E501) 上,我利用 DispatchQueue.global(qos: .background).async {...}
运行 while (true)
在后台循环:
func appStartDispatchQueue() {
DispatchQueue.global(qos: .background).async {
while(true) {
let networkStatus = Verification.onCompanyNetwork()
DispatchQueue.main.async {
self.onNetwork = networkStatus
}
sleep(3)
}
}
}
Verification.onCompanyNetwork()
正在通过 bash 脚本运行 ping,以查看公司网络上的服务器是否有响应。
我需要这个线程始终在后台运行这个应用程序 - 所以即使它失败,我如何捕获异常并确保线程再次启动?现在我什至不确定为什么线程失败......
到目前为止发现的两个崩溃场景:
完整的错误消息如下:
Crashed Thread: 1 Dispatch queue: com.apple.root.background-qos
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to set posix_spawn_file_actions for fd -1 at index 0 with errno 9'
terminating with uncaught exception of type NSException
abort() called
Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff339d9ecd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff5fa91720 objc_exception_throw + 48
2 CoreFoundation 0x00007fff339d9cff +[NSException raise:format:] + 201
3 Foundation 0x00007fff35ccf581 -[NSConcreteTask launchWithDictionary:error:] + 3236
4 AdminAccess 0x000000010f268b32 _T011AdminAccess9ScriptingC12shellCommandSSSgSS0D4Path_SaySSG9argumentstFZ + 370
5 AdminAccess 0x000000010f266e20 _T011AdminAccess9ScriptingC13runBashScriptS2S10scriptName_SS3argtFZ + 32496
6 AdminAccess 0x000000010f25779b _T011AdminAccess12VerificationC16onCompanyNetworkSbyFZ + 107
7 AdminAccess 0x000000010f26a834 _T011AdminAccess11AppDelegateC21appStartDispatchQueueyyFyycfU_ + 36
8 AdminAccess 0x000000010f26a99d _T011AdminAccess11AppDelegateC21appStartDispatchQueueyyFyycfU_TA + 13
9 AdminAccess 0x000000010f26aa1d _T0Ieg_IeyB_TR + 45
10 libdispatch.dylib 0x00007fff60b10d53 _dispatch_call_block_and_release + 12
11 libdispatch.dylib 0x00007fff60b11dcf _dispatch_client_callout + 8
12 libdispatch.dylib 0x00007fff60b1fe80 _dispatch_root_queue_drain + 671
13 libdispatch.dylib 0x00007fff60b204bd _dispatch_worker_thread2 + 90
14 libsystem_pthread.dylib 0x00007fff60d526dd _pthread_wqthread + 619
15 libsystem_pthread.dylib 0x00007fff60d52405 start_wqthread + 13
Thread 0:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff60c9917a mach_msg_trap + 10
1 libsystem_kernel.dylib 0x00007fff60c996d0 mach_msg + 60
2 com.apple.CoreFoundation 0x00007fff339230c2 __CFRunLoopServiceMachPort + 337
3 com.apple.CoreFoundation 0x00007fff33922611 __CFRunLoopRun + 1654
4 com.apple.CoreFoundation 0x00007fff33921d48 CFRunLoopRunSpecific + 463
5 com.apple.HIToolbox 0x00007fff32bb8ab5 RunCurrentEventLoopInMode + 293
6 com.apple.HIToolbox 0x00007fff32bb87eb ReceiveNextEventCommon + 618
7 com.apple.HIToolbox 0x00007fff32bb8568 _BlockUntilNextEventMatchingListInModeWithFilter + 64
8 com.apple.AppKit 0x00007fff30e73363 _DPSNextEvent + 997
9 com.apple.AppKit 0x00007fff30e72102 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1362
10 com.apple.AppKit 0x00007fff30e6c165 -[NSApplication run] + 699
11 com.apple.AppKit 0x00007fff30e5b8a3 NSApplicationMain + 780
12 mace.AdminAccess 0x000000010f26be6d main + 13 (AppDelegate.swift:18)
13 libdyld.dylib 0x00007fff60b5fed9 start + 1
Thread 1 Crashed:: Dispatch queue: com.apple.root.background-qos
0 libsystem_kernel.dylib 0x00007fff60c9f23e __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff60d55c1c pthread_kill + 285
2 libsystem_c.dylib 0x00007fff60c081c9 abort + 127
3 libc++abi.dylib 0x00007fff5e289231 abort_message + 231
4 libc++abi.dylib 0x00007fff5e2893cd default_terminate_handler() + 265
5 libobjc.A.dylib 0x00007fff5fa93c87 _objc_terminate() + 97
6 libc++abi.dylib 0x00007fff5e294dfe std::__terminate(void (*)()) + 8
7 libc++abi.dylib 0x00007fff5e294e73 std::terminate() + 51
8 libdispatch.dylib 0x00007fff60b11de3 _dispatch_client_callout + 28
9 libdispatch.dylib 0x00007fff60b1fe80 _dispatch_root_queue_drain + 671
10 libdispatch.dylib 0x00007fff60b204bd _dispatch_worker_thread2 + 90
11 libsystem_pthread.dylib 0x00007fff60d526dd _pthread_wqthread + 619
12 libsystem_pthread.dylib 0x00007fff60d52405 start_wqthread + 13
Thread 2:: com.apple.NSEventThread
0 libsystem_kernel.dylib 0x00007fff60c9917a mach_msg_trap + 10
1 libsystem_kernel.dylib 0x00007fff60c996d0 mach_msg + 60
2 com.apple.CoreFoundation 0x00007fff339230c2 __CFRunLoopServiceMachPort + 337
3 com.apple.CoreFoundation 0x00007fff33922611 __CFRunLoopRun + 1654
4 com.apple.CoreFoundation 0x00007fff33921d48 CFRunLoopRunSpecific + 463
5 com.apple.AppKit 0x00007fff30e7bf89 _NSEventThread + 160
6 libsystem_pthread.dylib 0x00007fff60d53305 _pthread_body + 126
7 libsystem_pthread.dylib 0x00007fff60d5626f _pthread_start + 70
8 libsystem_pthread.dylib 0x00007fff60d52415 thread_start + 13
Thread 3:
0 libsystem_pthread.dylib 0x00007fff60d523f8 start_wqthread + 0
1 ??? 0x0000000054485244 0 + 1414025796
Thread 4:
0 libsystem_pthread.dylib 0x00007fff60d523f8 start_wqthread + 0
1 ??? 0x0000000000000903 0 + 2307
Thread 1 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x00007000054b9000 rcx: 0x00007000054b88b8 rdx: 0x0000000000000000
rdi: 0x0000000000002703 rsi: 0x0000000000000006 rbp: 0x00007000054b88f0 rsp: 0x00007000054b88b8
r8: 0x00007000054b8778 r9: 0x00007000054b8950 r10: 0x0000000000000000 r11: 0x0000000000000206
r12: 0x0000000000002703 r13: 0x0000003000000008 r14: 0x0000000000000006 r15: 0x000000000000002d
rip: 0x00007fff60c9f23e rfl: 0x0000000000000206 cr2: 0x00007fff93949188
最佳答案
最好的方法是使用 https://github.com/ashleymills/Reachability.swift
在此链接中,您将看到如何始终请求 google.com 服务器。
有很多方法可以做到这一点
let hostReachability = Reachability(hostName:"www.apple.com")
hostReachability.startNotifier()
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "reachabilityChanged:",
name: kReachabilityChangedNotification,
object: nil)
它将避免您使用 while(true) 或类似难以处理的东西。
enum NetworkStatus {
case notReachable, reachableViaWiFi, reachableViaWWAN
}
var currentReachabilityStatus: NetworkStatus
关于swift - 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因 : 'Failed to set posix_spawn_file_actions for fd -1 at index 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54405568/
我是 C 语言新手,我编写了这个 C 程序,让用户输入一年中的某一天,作为返回,程序将输出月份以及该月的哪一天。该程序运行良好,但我现在想简化该程序。我知道我需要一个循环,但我不知道如何去做。这是程序
我一直在努力找出我的代码有什么问题。这个想法是创建一个小的画图程序,并有红色、绿色、蓝色和清除按钮。我有我能想到的一切让它工作,但无法弄清楚代码有什么问题。程序打开,然后立即关闭。 import ja
我想安装screen,但是接下来我应该做什么? $ brew search screen imgur-screenshot screen
我有一个在服务器端工作的 UDP 套接字应用程序。为了测试服务器端,我编写了一个简单的 python 客户端程序,它发送消息“hello world how are you”。服务器随后应接收消息,将
我有一个 shell 脚本,它运行一个 Python 程序来预处理一些数据,然后运行一个 R 程序来执行一些长时间运行的任务。我正在学习使用 Docker 并且我一直在运行 FROM r-base:l
在 Linux 中。我有一个 c 程序,它读取一个 2048 字节的文本文件作为输入。我想从 Python 脚本启动 c 程序。我希望 Python 脚本将文本字符串作为参数传递给 c 程序,而不是将
对于一个类,我被要求编写一个 VHDL 程序,该程序接受两个整数输入 A 和 B,并用 A+B 替换 A,用 A-B 替换 B。我编写了以下程序和测试平台。它完成了实现和行为语法检查,但它不会模拟。尽
module Algorithm where import System.Random import Data.Maybe import Data.List type Atom = String ty
我想找到两个以上数字的最小公倍数 求给定N个数的最小公倍数的C++程序 最佳答案 int lcm(int a, int b) { return (a/gcd(a,b))*b; } 对于gcd,请查看
这个程序有错误。谁能解决这个问题? Error is :TempRecord already defines a member called 'this' with the same paramete
当我运行下面的程序时,我在 str1 和 str2 中得到了垃圾值。所以 #include #include #include using namespace std; int main() {
这是我的作业: 一对刚出生的兔子(一公一母)被放在田里。兔子在一个月大时可以交配,因此在第二个月的月底,每对兔子都会生出两对新兔子,然后死去。 注:在第0个月,有0对兔子。第 1 个月,有 1 对兔子
我编写了一个程序,通过对字母使用 switch 命令将十进制字符串转换为十六进制,但是如果我使用 char,该程序无法正常工作!没有 switch 我无法处理 9 以上的数字。我希望你能理解我,因为我
我是 C++ 新手(虽然我有一些 C 语言经验)和 MySQL,我正在尝试制作一个从 MySQL 读取数据库的程序,我一直在关注这个 tutorial但当我尝试“构建”解决方案时出现错误。 (我正在使
仍然是一个初学者,只是尝试使用 swift 中的一些基本函数。 有人能告诉我这段代码有什么问题吗? import UIKit var guessInt: Int var randomNum = arc
我正在用 C++11 编写一个函数,它采用 constant1 + constant2 形式的表达式并将它们折叠起来。 constant1 和 constant2 存储在 std::string 中,
我用 C++ 编写了这段代码,使用运算符重载对 2 个矩阵进行加法和乘法运算。当我执行代码时,它会在第 57 行和第 59 行产生错误,非法结构操作(两行都出现相同的错误)。请解释我的错误。提前致谢:
我是 C++ 的初学者,我想编写一个简单的程序来交换字符串中的两个字符。 例如;我们输入这个字符串:“EXAMPLE”,我们给它交换这两个字符:“E”和“A”,输出应该类似于“AXEMPLA”。 我在
我需要以下代码的帮助: 声明 3 个 double 类型变量,每个代表三角形的三个边中的一个。 提示用户为第一面输入一个值,然后 将用户的输入设置为您创建的代表三角形第一条边的变量。 将最后 2 个步
我是新来的,如果问题不好请见谅 任务:将给定矩阵旋转180度 输入: 1 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 输出: 16 15 14 13 12 11
我是一名优秀的程序员,十分优秀!