By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Error under Cygwin - threading module

P: n/a
Hello,

Nothing relevant found on Google for this, so I'm asking here. I wrote
a short script that launches several threads (parallel download using
urllib.urlretrieve in this case). Sometimes when I launch my script
under Cygwin, I get strange error messages like:

2 [win] python 1912 Winmain: Cannot register window class

Sometimes all of the threads run OK, otherwise after the "correct"
ones finish the console stops responding anyway. No problems directly
under Windows, and /lib/python2.3/test/test_threading.py works fine
too. What is wrong?

Here is the script:

---- wp_retr.py ----

#!/usr/bin/env python

"""Retrieve files from the list, give new names if present in list."""

from __future__ import division

import re
import urllib
import threading
import time
import sys
class Download:
def __init__(self, url, name):
self.url = url
self.name = name
self.last_check = 0.0
class DownloadBag:
def __init__(self, downloads):
self._downloads = []
for url, name in downloads:
self._downloads.append(Download(url, name))
def start(self):
threads = []
for d in self._downloads:
p = self._createProgress(d)
thargs = (d.url, d.name, p)
th = threading.Thread(target=urllib.urlretrieve,
args=thargs)
threads.append(th)
th.start()
return threads
def _progress(self, download, blocks, blk_size, total):
t = time.time()
if t - download.last_check > 5:
if total != -1:
print "%s -> %s: %2.1f%%" % (download.url,
download.name,

blocks*blk_size/total*100)
else:
print "%s -> %s: %d bytes" % (download.url,
download.name,
blocks*blk_size)
download.last_check = t
def _createProgress(self, download):
def progf(blocks, blk_size, total):
self._progress(download, blocks, blk_size, total)
return progf
if __name__ == "__main__":
spcre = re.compile(r"(.*?)\s+(.*)$")
slashre = re.compile(r"(?:.*)/(.*?)$")
f = file(sys.argv[1]) #"filelist.txt")
filelist = []
for line in f:
line = line.strip()
m = spcre.match(line)
if m:
url, name = m.groups()
else:
m = slashre.match(line)
if m:
url, name = line, m.group(1)
else:
print "Incorrect line format:\n%s" % line
continue
filelist.append((url, name))
f.close()
db = DownloadBag(filelist)
threads = db.start()
for t in threads:
t.join()

----

and here is an example input file (run as python filelist.py
filelist.txt):

---- filelist.txt ----

http://www.gnu.org/software/bash/manual/bashref.html
http://www.gnu.org/software/make/man...mono/make.html

----

TIA,

AdSR
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
AdSR,

On Thu, Jan 22, 2004 at 02:19:31PM -0800, AdSR wrote:
Nothing relevant found on Google for this, so I'm asking here. I wrote
a short script that launches several threads (parallel download using
urllib.urlretrieve in this case). Sometimes when I launch my script
under Cygwin, I get strange error messages like:

2 [win] python 1912 Winmain: Cannot register window class

Sometimes all of the threads run OK, otherwise after the "correct"
ones finish the console stops responding anyway.
FWIW, I cannot reproduce the above problem under:

$ cygcheck -cd cygwin python
Cygwin Package Information
Package Version
cygwin 1.5.5-1
python 2.3.2-1

and

Windows 2000 SP4

What Cygwin, Python, Windows versions are you using?

Have you tried a recent Cygwin snapshot? Some pthread bugs have been
fixed since 1.5.5-1.
No problems directly under Windows,
What does the above mean? Under Win32 Python? Or, under cmd.exe?
What is wrong?


Sorry, I don't know.

Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

Jul 18 '05 #2

P: n/a
AdSR,

On Tue, Jan 27, 2004 at 09:46:36AM -0500, Jason Tishler wrote:
On Thu, Jan 22, 2004 at 02:19:31PM -0800, AdSR wrote:
Sometimes when I launch my script under Cygwin, I get strange error
messages like:

2 [win] python 1912 Winmain: Cannot register window class

Sometimes all of the threads run OK, otherwise after the "correct"
ones finish the console stops responding anyway.


FWIW, I cannot reproduce the above problem under:

$ cygcheck -cd cygwin python
Cygwin Package Information
Package Version
cygwin 1.5.5-1
python 2.3.2-1

and

Windows 2000 SP4


I "spoke" too soon -- I was able to reproduce the problem after 160
iterations. Please try the latest snapshot:

http://cygwin.com/snapshots/

and report back whether or not this solves your problem.

Thanks,
Jason

--
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.