使用线程和红宝石机械化安全吗? [英] is using threads and ruby mechanize safe?

查看:68
本文介绍了使用线程和红宝石机械化安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人看到过很多这样的错误:

Does anyone ever see a lot of errors like this:

Exception `Net::HTTPBadResponse' at /usr/lib/ruby/1.8/net/http.rb:2022
- wrong status line: _SOME HTML CODE HERE_

何时使用螺纹并机械化?我相对确定这是 线程和net/http库之间有一些不良行为,但是确实 任何人都对您想要的线程上限有任何建议 在使用mechanize/nethttp时立即运行?以及由于rescue Net::HTTPBadResponse不起作用,如何捕获这种异常?

When using threads and mechanize? I'm relatively certain that this is some bad behavior between threads and the net/http library, but does anyone have any advice as far as the upper limit of threads you want to run at once when using mechanize/nethttp? And how can I capture this kind of exception because rescue Net::HTTPBadResponse doesn't work?

推荐答案

在Mechanize中,这可能是非线程安全的,但是我可以想到可能导致相同问题的其他错误.如果您正在使用持久连接,那么我将首先禁用它们.接下来要做的是查看代码,并确保对要处理的对象保持谨慎.如果您的应用程序有多个与常见对象混为一谈的线程,则可能会破坏本来是线程安全的库.

This could be something non-thread-safe in Mechanize, but I can think of other bugs that might cause the same problem. I'd start by disabling persistent connections, if you're using them. The next thing to do is to look at your code, and make sure that you're being careful with the objects you handle. If your application has multiple threads mucking about with common objects, that can break a library that would be otherwise thread-safe.

如果某个地方存在线程问题,则可以安全使用的线程上限为1.再者,您只是在权衡问题发生的频率,而不是是否发生问题是否发生.

If there is a threading problem somewhere, the upper limit of threads you can use safely is 1. Any more, and you're just making a trade-off about how often you want the problem to occur, rather than whether it occurs or not.

这篇关于使用线程和红宝石机械化安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆