473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

cookielib and urllib2: thread-safe?

I'm writing a test script in python for pulling web pages from a web
server using urllib2 and cookielib. Since the main thing I am testing is
what happens when concurrent requests are made to the web server, I need
to make several requests concurrently, which I'll do from different
threads in my python script. So the important question is: are cookielib
and urllib2 thread safe? Are there any precautions that apply to using
these libs in a multi-threaded context?

thanks!
alex
Jul 18 '05 #1
1 3563
Alex Hunsley <la**@tardis.ed.ac.molar.uk> writes:
I'm writing a test script in python for pulling web pages from a web
server using urllib2 and cookielib. Since the main thing I am testing
is what happens when concurrent requests are made to the web server, I
need to make several requests concurrently, which I'll do from
different threads in my python script. So the important question is:
are cookielib and urllib2 thread safe? Are there any precautions that
apply to using these libs in a multi-threaded context?


urllib2: For HTTP, yes, AFAIK. For other protocols, eg. FTP, perhaps
not.

cookielib: No. It's currently thread-broken, simply because I've
never had reason to do threaded stuff with it. There is thread
synchronization code in there, but I have little doubt that it's
broken, because it's untested (I should have removed the
synchronization code entirely, in fact, since nobody volunteered to
test & fix before release: unfortunately the first beta caught me by
surprise...).

I won't be making it threadsafe, so don't wait for me to do it. I'm
happy to help others do so. Nothing especially hard for somebody with
plenty of thread experience to do, AFAIK.

I had thought part of a patch had gone in which stated this
thread-unsafety very prominently in the cookielib module docs, but it
seems that never happened, or at least not in time for 2.4.0 -- eek!
John
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jacek Trzmiel | last post by:
Hi, I have a problem with using urllib2 with threading module under Cygwin. $ cygcheck -cd cygwin python Cygwin Package Information Package Version cygwin 1.5.5-1...
1
by: Doug Farrell | last post by:
Hi all, I'm trying to build a web page crawler to help us build our websites, which are driven by static pages after they are called the first time. Anyway, I can use urllib2.urlopen() no...
0
by: C. Titus Brown | last post by:
Hi all, just spent some time playing with cookielib in Python 2.4, trying to get the cookielib example to work with my mailman admindb page. The problem was that cookies weren't getting saved....
2
by: sri2097 | last post by:
Hi, I need to get to a particular page in a website. The site uses cookeis and naturally I had to use cookielib since urllib2 does not support cookies. But even after adding the cookies to the...
1
by: BJörn Lindqvist | last post by:
Hello, I have some very serious trouble getting cookes to work. After a lot of work (urllib2 is severly underdocumented, arcane and overengineerd btw) I'm finally able to accept cookes from a...
6
by: Alessandro Fachin | last post by:
Hi, i am trying to forge a new cookie by own with cookielib. But i don't still have success. This a simply code: import cookielib, urllib, urllib2 login = 'Ia am a cookie!' cookiejar =...
3
by: Olivier Oost | last post by:
Hi, I need to login to a online forum, like a phpbb forum, and leave a message there. I figured I need to use cookielib, but the documentation of cookielib is not very clear to me. I tried to...
1
by: JD Smith | last post by:
Greetings: My cookiejar contains the cookie that I need however when I do cj.save(file) it does not actually save out to the cookies.lwj Does anyone have any clue what would keep this from...
2
by: Joshua Kugler | last post by:
Standard disclaimer: read, googled, read some more. If you have a link, please free free to point me there. I'm using HTTPlib to construct some functional tests for a web app we're writing. ...
2
by: Felipe De Bene | last post by:
Hi There, I'm trying to run an App I wrote in Python 2.5.2 in Jython 2.2.1 and everything works fine except when I try to import the Standard CPython's cookielib. I know this may sound stupid, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.