[Mechanize-users] Mechanize/Nokogiri Thread Safe?
aaron.patterson at gmail.com
Fri Sep 4 11:29:52 EDT 2009
On Fri, Sep 4, 2009 at 8:24 AM, Aaron Starr<astarr at wiredquote.com> wrote:
> This question is probably specifically for Aaron Patterson, but if anyone
> else has experience with it, I'd love the info.
> I have a long-running process that takes incoming requests, does some
> mechanize nonsense, and returns a result.
> I'd like to spin off a thread for each request, so the same process could
> handle several simultaneous requests and thereby conserve some resources on
> the server.
> So, is Mechanize thread-safe? Is Nokogiri?
Nokogiri is thread safe. For mechanize, it depends on how you use it.
If you create one agent that is shared among threads, you will get
unexpected results. The reason being that the history is stored on
the agent, so if two threads add to the history, the referrer can end
up being incorrect. One agent per thread, and you should be fine.
More information about the Mechanize-users