POP connection timeout.


I am have written an application that queries a POP mailbox and
downloads messages. When the application tries to connect to the mail
server, but takes too long (eg. longer than 60 seconds) I want to have
it time out.

Something like

pop = poplib.POP3(POPHOST, POPPORT)
except someerror, err:
print "Connecting to mail box has timed out:\n", err

I know that in python 2.5 I could pass an additional timeout parameter
to the above statement ( ie: pop = poplib.POP3(POPHOST, POPPORT,
TIMEOUTINSECONDS), but I am using python 2.4.

Can anyone help me implement this timeout functionality.

Posted On: Wednesday 7th of November 2012 12:47:01 PM Total Views:  667
View Complete with Replies

Related Messages:

nested popen4   (180 Views)
Hi all, I know it's a kind of bizarre question but here I go: I want to execute an script using popen4. This script executes a command in turn using popen4 too. The first one throws a 256 exit code. Any suggestions
wxpython ms-dos black window popping up in background   (390 Views)
platform: windows xp professional, python 2.5, wxpython When I double-check on my program file (for simplicity I'll be using this code below), I see the window just fine. But the ms-dos black window pops up in the background. On Linux, no issues at all. How can I get rid of that ms-dos black window in the background something I need to add to my code a setting to adjust in windows thanks in advance. #!/usr/bin/python import wx appwx = wx.App() frame = wx.Frame(None, -1, '') frame.Show() appwx.MainLoop()
pop langs website ranking   (169 Views)
In February, i spent few hours researching the popularity of some computer language websites. (The message can be found here: ) In that post, one question i puzzeled over is why's traffic is surprisingly high, since the site doesn't seems to host forums, computer lang documentation, or wiki type of thing, yet it is ranked higher than, which actually host online forum, faq, documentation, news etc. I wrote: ------------ 48153 (lisp bigwig, but huh) 49104 80060 Me! ------------- Compared to, it's a ranking difference about 32 thousand! Today, while checking the web ranking site, they seems to have updated their ranking algorithm to be more fair, as opposed basing it solely on a browser toolbar that users install. So i went over to my essay and checked the ranking again of sites i reported. I have spent only about 20 min to cursorily go thru the sites i reported before. It appears that, in general, the order of sites that i listed ROUGHLY remains unperturbed, but the specific ranking ordinal has changed rather significantly. However, there's a big surprise. My website is now actually ranked higher than ! LOL. Paul Graham Bah humbug. Painters == Hackers Fuck ya ass. Arc Eat shit and die. PS: not having no confidence of myself, but i note that is now marginally ranked higher than and, both of which host forum/blog/wiki, news, docs, etc., while my website don't do any of these and is all static html pages. For those unflagging, alternative web ranking site is . I'll be doing some research sometimes soon on this. Xah , Gerry Ford wrote: > "Paul McGuire" wrote in message > > On Apr 22, 4:41 pm, "" wrote: >> In February, i spent few hours researching the popularity of some >> computer language websites. >> > I seem to recall this exact same post from *last* February. > > --->I remember it too. Xah is quite the self-promoter. Massive > cross-posters don't have anything to say for me. So don't do it. -- Lew
Pygame, how to show window without loop? no loop=popupand close...   (257 Views)
Im using PyGame to draw images of graphs and trees. Howver right now i am looping using: while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() screen.fill(screencolor), linecolor, (500, 20), 12, 0) draw((500, 20), 3) pygame.display.flip() if i do screen.fill(screencolor), linecolor, (500, 20), 12, 0) draw((500, 20), 3) pygame.display.flip() it just pops up and closes. how can i make it stay until i close it without using a loop
"env" parameter to "popen" won't accept Unicode on Windows - minorUnicode bug   (138 Views)
I passed a dict for the "env" variable to Popen with Unicode strings for the dictionary values. Got: File "D:\Python24\lib\", line 706, in _execute_child TypeError: environment can only contain strings It turns out that the strings in the "env" parameter have to be ASCII, not Unicode, even though Windows fully supports Unicode in CreateProcess. John Nagle
if you want do business on the internet .pls go,if you want buy muchpopular and inexpensive price pls go   (186 Views)
if you want do business on the internet .pls go,if you want buy much popular and inexpensive price pls go 2008 new year, 2008 Good news In order to greet the new year the arrival, company in new year grand preferential policy: 1. The shopping full 500USD customer, may enjoy the company to provide 90% discount the preferential benefit, primary proxy. 2. The shopping full 1000USD customer, may enjoy the company to provide 80% discount the preferential benefit, the company simultaneously provides the intermediate proxy website, for your country region this city minute agent. 3. The shopping full 2000USD customer, may enjoy the company to provide 70% discount the preferential benefit, the company simultaneously provides the high-level proxy website, for your country region this city general agent. This agent only provides a quota of people in this urban company. .every one, our company have much cheap product . please visit our web, And chose the product of your like ,let go ,hope you shiping happy ,Go Nike Air Jordan 1 ,Nike Air Jordan 2 Shoes,Nike Air Jordan 3,Nike Air Jordan 4 Shoes ,Nike Air Jordan 5 Chaussure Shoes,Nike Air Jordan 6 Catalog ,Nike Air Jordan 7 Shoes Catalog , Nike Air Jordan 8 Customized ,Nike Air Jordan 9 Shoes Customized ,Nike Air Jordan 10 Wholesalers,Nike Jordan 11 Shoes Wholesalers,Nike Air Jordan 12 retailer,Nike Air Jordan 13 Shoes Factory ,Nike Air Jordan 14 Shoes Sell,Nike Air Jordan 16 Exporter ,Nike Air Jordan 17 Shoes Exporter, Nike Air Jordan 18 Offer, Nike Air Jordan 19 Shoes Offer,Nike Air Jordan 20 Manufacture,Nike Jordan 21 Shoes Manufacture,Nike Jordan 22 CUSTOMIZED , We Import&Export&Trading&Retail&sell&buy&distribution& Wholesale Nike footwear and Nikes Sneakers Jordans Sneakers to this market: USA,America,US,United States,UK,England,United Kingdom,IT,Italy, NT,Netherlands,China,Chinese,Germany,DE,Greece,GR,France, FR,Spain,Portugal,Switzerland,Switzerland,Brazil,Chile,Peru,C Korea,Australia,Hongkong,Canada,Mexico,Etc Nike shoes | china nike shoes | air jordan sneakers | cheap gucci shoes | cheap prada sneakers | gucci sneakers | mix jordan sneakers | chanel sandals | gucci sandals | dior sandals | wholesale jordan sneakers | nike running shoes | nike stock shoes | air jordan at whlesale price | nike shoes air jordan supplier from in china | Lacoste Trainers | puma trainers | louis vuitton purse | prada purse | gucci handbags | chanel purse | coach purse | nike bas kerball shoes | Nike Sneakers| cheap nike sneakers | nike shoes from china | nike replica | copy nike sneakers | nike factory stores | nike stores Nike wholesale - Nike shoes wholesale nike jordan sneakers wholesale We (http: // ) Wholesale Cheap Jordan Shoes,Michael Jordan Shoes,Nike Jordan Basketball shoes, ... Jordan Shoes,Air Jordan Sneakers,Air Jordan Wholesale of the Air Jordan sneakers have Nike Air in the shoes.Authentic quality Jordan Sneakers Custom Jordan Sneakers Wholesale Jordan Sneakers gucci sneakers prada sneakers in ,lv chanel coach dior DG DSQUARED2 DIESEL,miumiu handbags sneakers,shoes,t- shirts,jeans,jackets.We sale new Nike Sneakers,Air Jordan Sneakers,AIR FORCE 1S,Nike Dunks SB,Bape Sta from nike outlets and factory stores,also Nike wholesale-Jordan Shoes,sneakers! china online store! Cheap Lacoste Trainers Please,Lacoste Trainers for Women,Lacoste Shoes Online,Lacoste Shoes for Women,Buy Lacoste Trainers Online,Lacoste Sneakers Lacoste Footwear,Black Lacoste Trainers,Lacoste Trinity Trainers Lacoste Leisure ***** cheap nike dunks,cheap gucci sneakers cheap sunglasses factory,wholesale nike tshirts,cheap air jordans nike sb china wholesale,cheap puma sneakers,sneaker wholesale china,jordans sneakers,gucci shirts wholesale,cheap bape trainers,shoe wholesalers in china,cheap nike sneakers,DISCOUNT nike SNEAKERS,Tennis Sneakers,gucci Sneakers, Prada Sneakers,Shoes Jordan's + Wholesale,jordan wholesale manufacturers,nike customes,cheap wholesale jordans *****cheap tiffany necklace,gucci shoes shop,Wholesale Distributor Authentic Nike Shoes,wholesale air forces and jordans,dsquared manufacturers,dsquared womens shoes,dsquared2 jeans,dsquared2 shoes ed hardy caps,ed hardy caps cheap,ed hardy for cheap,ed hardy hats for cheap addidas wholesalers distributor bulk air force ones for sale Burberry Handbags made in China BUY ARMANI SHOES Buy holesale from china GUCCI buy jordans made in china buy nike shoes at wholesale price
pop langs website ranking   (174 Views)
while doing my website's traffic report, i did some research on major computer lang or tech website ranking. Here's the result ranked by (some non-lang tech sites are given just for comparison): 550 (largely due to online doc and forum) 900 (java doc and forum) 1122 1223 (forum) 1296 (online doc, forum) 7328 (massive docs, mailing list archives) 9065 (online doc, mathworld etc) 9410 (python doc and prob forums) 26067 (perl doc, forum) 48153 (lisp bigwig, but huh) 49104 80060 Me! 118703 130568 (lisp bigwig) 292598 377906 (common lisp doc) 529551 (pop common lisp book) 880284 The list is not that surprising. Many top ones are due to the popularity of the lang, but also because their site hosts the lang's documentation and discussion forum (or wiki,blogs). Hosting a web forum are likely to increase traffic some 10 or 100 fold. Questions: is unusually high. What's up with that at 9k seems also unusally high, compare that with online doc and forum is only 26k. has mailing list archives... maybe blogs too but am not sure it has forums... still the gab seems surprising. Even perl is not much talked about these days, but i'm guessing its market share is at least still 10 or 100 times of python... If any one so wishes, add entries to the above list. Xah
os.popen does not seem to catch stdout   (225 Views)
, I've been banging my head against this for a day, and I can't take it anymore. It's probably a stupid error, but I don't see where. I'm trying to use Python to call an external program, and then catch and process the output of that program. Seems simple enough. The command I'm trying to run, in the test, is: "/Users/zane/svn/stress/satstress/satstress -r1.561e+06 -a5 -s45000 - e0 -R6.709e+08 -g1.31472 -m1.8987e+27 -Q57100.1 -n0.333355 -Y9.29881e +09 -k1e+22 -Z1.19173 -z-6.293e-05 -V0.309434 -v-2.903e-05 -W1.81305 - w-0.00418645 -U0.474847 -u-0.00276624 -C /tmp/18_tmp.gen -b 60" When I run it at my zsh prompt, I get the expected output. If I let ss_cmd equal the above string within ipython (or the standard python interactive interpreter): ss_outlines = os.popen(ss_cmd).readlines() ss_outlines contains the same output I saw when I ran the command at my zsh prompt, one line per list element, as expected. However, when I try doing the same thing from within a program, it fails. ss_outlines is an empty list. I've tried using subprocess.Popen(), and, and subprocess.check_call(), and all have yielded similar results. I did find, however, that the return value python is getting from the program I'm calling is different from what I get at the command line (I get 0, python gets -11). Does this ring a bell for anyone I'm using Python 2.5.1 on a Mac running OS X 10.5.
Re: Easiest way to get exit code from os.popen()?   (284 Views)
On Wed, 24 Oct 2007 19:07:44 -0000, mrstephengross wrote: >Hi folks. I'm using os.popen() to run a command; according to the >documentation, the filehandle.close() oepration is suppsoed to return >the exit code. However, when I execute something like "exit 5", >close() returns 1280. Here's the code: > > pipe = os.popen("exit 5") > print pipe.close() # prints 1280 > >Am I doing something wrong Is there an easier way to get the exit >code >>> import os >>> os.WEXITSTATUS(1280) 5 >>> Jean-Paul
How popular is Django ?   (155 Views)
Hi! I was surprised when I did a google-groups search for python, ( ) it shows these groups: comp.lang.python with about 11000 users, and second, Django users Discussion group for Django users. Django is a high-level Python Web ... with 6500 members !!!! I cannot believe that django is *that* popular ... where am I going wrong Cheers, Sebastian Haase
wx.ToplevelWindow.SetIcon: Native MS Windows error dialog pops upin wxPython app, no exception raised, no stack trace   (229 Views)
, I wrote a small program that works uses wxPython. The same application works on Linux and Windows. When I start it from MS Windows, I see this error message appearing each time I open a window: --------------------------- Warehouseclient Error --------------------------- Can't load image from file '': file does not exist. --------------------------- OK --------------------------- The message box itself is a native MS Windows dialog. Otherwise the program works fine, just here is this annoying message. There is no exception raised in the Python program. Nothing printed on console. I figured out that this happens only when I set the icon of the window using this code: self.SetIcon(icon) However, the error dialog is not displayed right after the SetIcon call and no exception is raised. The dialog is displayed after __init__ has been called, and probably before EVT_SHOW gets called. Documentation of SetIcon ( says that it is safe to delete the icon after calling this function. Now here are the wreid things: 1. The icon is displayed correctly in the left top corner, so where is the error 2. The error message complains about a file. What has wx.ToplevelFrame.SetIcon do with files I'm using: Windows XP Professional, Python 2.5, wxPython 2.8
mode parameter in popen2-4   (166 Views)
In the popen docs, a file like object is returned, and may be read to or written to depending on the 'mode' parameter ('r', or 'w'). Why is the mode parameter needed for popen2 and greater, when both a stdin and stdout object is returned One wouldn't want to 'append' to a stream.... is it because binary mode can still be turned on and off this way
subprocess.popen question   (213 Views)
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with the old module and cmd is the command I wish to try) all the output seems to be returned as one line (at least when I run the program in spe). import subprocess from os import system cmd = """gawk -f altertime.awk -v time_offset=4 -v outfile="testdat.sco" "i1.sco" """ #subprocess.Popen. last_line = subprocess.Popen(['gawk.exe'], stdout=subprocess.PIPE).communicate()[0] xx = 0 for line in last_line: xx = xx + 1 if xx < 2: print line print str(xx)
poplib.retr doens't flag message as read   (246 Views)
, I am trying to use the poplib library to get emails using the retr method. The small program bellow works but the message aren't flagged as read which puzzles me. I believe the pop server is qmail 1.0.6 / vpopmail 5.2.1 and I am running the following script on Windows using Pyhton 2.5. import poplib import email pop = poplib.POP3('') pop.user('') pop.pass_('password') status, msg_list, octets = pop.list() for msg_number in [msg.split(' ')[0] for msg in msg_list]: status, lines, octets = pop.retr(msg_number) msg = email.message_from_string('\n'.join(lines)) if not msg.is_multipart() and msg.get_content_type() == 'text/plain': print msg.get('Subject') print msg.get_payload() pop.quit() Why aren't the message flagged as read Is there a way to manually mark them read
popen5: New POSIX process module   (259 Views)
I've written a new popen-like module for Python. This module overcomes several limitations with the old popen2 module, but also aims to be a generic module for starting and communicating with processes on POSIX systems. It can replace several older modules and functions, like: os.system os.spawn* os.popen* popen2.* commands.* This module features: * Cross-process exceptions: Exceptions happening in the child before the new process has started to execute are re-raised in the parent. This means that it's easy to handle exec() failures, for example. With popen2, it's impossible to detect if the execution failed. * A hook for executing customized code between fork and exec. This can be used for, for example, changing uid. * No implicit call of /bin/sh. This means that there is no need for escaping dangerous shell meta characters. * A communicate() method, which makes it easy to send stdin data and read stdout and stderr data, without risking deadlocks. * Support for connecting several subprocesses (shell "pipe"). The module is available from, or via anonymous CVS ( feedback is appreciated. /Peter strand
POP3 - Using poplib only shows the first few hundred messages in themailbox   (420 Views)
, I am trying to use POP3_SSL class of the poplib module to read email from my gmail account. I can connect just fine using the example here import getpass, poplib M = poplib.POP3('localhost') M.user(getpass.getuser()) M.pass_(getpass.getpass()) numMessages = len(M.list()[1]) for i in range(numMessages): for j in M.retr(i+1)[1]: print j That is the above sample code from the python doc. While everything works fine, the problem is that when I use the list() function it only returns about 400 messages starting from the beginning of my inbox. I have probably 10,000 emails in my gmail account. I don't see any pop3 object functions to "move" around the inbox or anything of the like. Could someone point me in the right direction I'm sure there must be something simple I am missing.
win32pipe.popen4 howto example   (232 Views)
trying to remind myself that running a subprocess under Win32 isn't a pain in the ass... ];^) ########################################################### #!/usr/bin/env python ''' original author credits: chris levis original sources found: from python docs, 17.4 popen2 -- Subprocesses with accessible I/O streams popen4(cmd [, bufsize[, mode]]) Executes cmd as a sub-process. Returns the file objects (child_stdout_and_stderr, child_stdin). -- New in version 2.0. If, o bufsize, is provided, it specifies the buffer size for the I/O pipes. o mode, is provided, the string 'b' or 't'; - 'b' required on Windows for binary read access - 't' (text mode) is default ''' ''' External test file. ---- start snippet --------- import sys print "hello, world" sys.exit(-1) ---- end snippet ----------- ''' import win32pipe; cmd = '' # open stdout pseudo file in textmode 't' (stdin,stdout) = win32pipe.popen4( cmd, 't' ); stdin.close(); output =; try: exitcode = stdout.close() or 0; except IOError: exitcode = ( -1 ); print output ## prints 'hello world' print exitcode ## print '-1'
popen hangs sporadically   (185 Views)
I have a script that calls the function write_tmpfile, which looks something like this: def write_tmpfile(f, tmpfile): # set-up code omitted in_f = popen("""grep -v '^\\[eof\\]$' %s |\ grep '[^[:space:]]' |\ sort -u""" % f) out_f = open(tmpfile, 'w') try: while 1: line = in_f.readline() if not line: break # i omit the code that munges line out_f.write(line) finally: in_f.close() out_f.close() The script calls this function several thousand times. (The average size of the input file f is 70K lines (0.5MB); the maximum size is about 35M lines, or 200MB.) This function works perfectly most of the time, but it deadlocks sporadically. (And it's a deadlock! The script can be stuck for hours, until I kill it.) I can't say for sure where the deadlock is happening (and I'd appreciate suggestions on how to pinpoint this), but I *think* it is at the in_f.readline() statement. So maybe the problem is with the pipe. (But FWIW, I've used exactly the same pipe in another script that processes the same set of files (but does not write a temporary file when it does this), and this script terminates without any problem. I.e. the input files are not too large for the pipe.) I suppose that I could use some timeout mechanism to unwedge the script when it deadlocks and then repeat the call to write_tmpfile, but I'd prefer to avoid the deadlock in the first place. I'd appreciate suggestions on how to troubleshoot and debug this thing. TIA! Kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded.
Using poplib to parse headers   (190 Views)
, I am writing a Python program to check email using POP3. I've tried the sample code from, and it works great. In other words, the code below successfully prints out my emails. import getpass, poplib, email M = poplib.POP3('') M.user('username') M.pass_('password') numMessages = len(M.list()[1]) for i in range(numMessages): for j in M.retr(i+1)[1]: print j M.quit() However, if I understand right, the Python poplib library will also parse the email for me so that I can iterate through the headers, body, etc, of each message, and use them in my program. I think the method I need to use is email.message_from_file, but I'm having difficulty getting it to work. Can anyone explain me how I would extend the above example to do this I tried to do this by using in the i loop the line: message = email.message_from_file(j) but I get the error: "AttributeError: 'str' object has no attribute 'readline'" Please forgive this very basic question. I do most of my programming in PHP and I'm just getting started with Python. Many
poplib - retr() getting stuck   (382 Views)
I am using poplib's retr() to fetch mails from my gmail account. It works fine, in some cases it gets stuck inside the retr() method and does not come out. From the logs I could find that when retr() is called, it stops executing further statements, nor does it throw an exceptions but simply stops. My code is roughly like the foll: try: print "1" mymsg = M.retr(msg_no) print "2" except poplib.error_proto, e: print "exception1" except Exception, e: print "exception2" What can be the reason for this Can anyone help me.