调试器停止在 ASIHTTPRequest 的 ScheduleReadStream 上,没有错误
调试器在 ASIHTTPRequest 的 ScheduleReadStream 方法中暂停,但不会产生错误。
更具体地说,它停在这条线上:
[[self readStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]];
无论我点击播放多少次,它都不会离开这条线或在控制台中报告任何错误。然而,我确实注意到,当我点击播放时,主线程会推进一些操作。
我设置的方式是,我有一个在后台线程上工作的下载器(因此当它从已完成的请求中接收到它时,它可以进行解析和图像操作)。此下载器对象使用 ASINetworkQueue
来安排请求。我想知道这是否会导致僵局。
下面是在解析刚刚完成的请求(不是队列的一部分)中的一些数据后将请求添加到队列中的代码片段。
- (void)requestFinished:(ASIHTTPRequest *)request
{
dispatch_async(serialQueue, ^{
NSData *responseData = [request responseData];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:responseData];
[parser setDelegate:self];
if ([parser parse]) {
//Add pending operations
for (NSNumber * key in self.currentRequests.keyEnumerator) {
//Unrelated code getting the request from a dictionary
[self.networkQueue addOperation:request];
}
[self.networkQueue go];
}
});
}
请注意,我还在整个代码中异步执行不相关的请求,这可能在填充/告知该队列的同时进行。
The debugger pauses within ASIHTTPRequest's scheduleReadStream method, but produces no errors.
More specifically, it's stopping on this line:
[[self readStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:[self runLoopMode]];
No matter how many times I hit play, it doesn't move off this line or report any errors in the console. I did notice that the main thread advances through some of its operations when I hit play, however.
The way I have things setup, I have a downloader that's working on a background thread (so it can do parsing and image manipulation when it receives it from the completed requests). This downloader object is using an ASINetworkQueue
to schedule the requests. I'm wondering if maybe this is causing a deadlock.
Here's the snippet of code that adds the requests to the queue after parsing some data from a request that just finished (not part of the queue).
- (void)requestFinished:(ASIHTTPRequest *)request
{
dispatch_async(serialQueue, ^{
NSData *responseData = [request responseData];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:responseData];
[parser setDelegate:self];
if ([parser parse]) {
//Add pending operations
for (NSNumber * key in self.currentRequests.keyEnumerator) {
//Unrelated code getting the request from a dictionary
[self.networkQueue addOperation:request];
}
[self.networkQueue go];
}
});
}
Note that I'm also doing unrelated requests asynchronously throughout the code, which could be going on at the same time as this queue is being filled/told to go.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。结果发现有一个
EXC_BAD_ACCESS
,但在 iPhone 上运行时并未显示。当在模拟器上运行时,它实际上显示正确。这种错误的访问是由于我没有使用initWithURL
方法,而是设置了 URL(因为在创建对象时我还没有可用的 URL)。一旦 URL 准备好并且一切都很好,我现在就调用initWithURL
。Figured it out. Turns out there was an
EXC_BAD_ACCESS
but it wasn't showing up when running on the iPhone. When running on the simulator it actually showed up properly. This bad access was due to the fact that I didn't use theinitWithURL
method, instead setting the URL (since when creating the object I didn't have the URL available yet). I callinitWithURL
now once the URL is ready and everything is good.