Error under Cygwin - threading module

A

AdSR

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/manual/html_mono/make.html
 
J

Jason Tishler

AdSR,

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
 
J

Jason Tishler

AdSR,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top