Re: A lock that times out but doesn't poll
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Python, of course, is unsuitable for many hard realtime systems, > and if you're using Windows you are probably on the wrong platform > in the first place. Well, there is that. The platform I'm using is a realtime operating system, but it has a Windoze lookalike API for OS functions like threads, semaphores, critical sections, events, and whatnot. [OT] I don't draw any distinction between "soft" and "hard" realtime. I've never seen definitions for those terms that I thought were useful. If some operations must be performed within a certain time window, to me that's realtime, neither hard, soft, smooth, lumpy, or just right. A realtime operating system has guaranteed latency. Depending on the application, it does not necessarily have to be fast. I have an application that runs fine on a realtime OS, but fails eventually under MS Windows running on a processor that's 3x as fast. [/OT] > The bar for putting things in the main distribution should be > very, very high. Agreed. IMHO the bar was not set high enough for the current threading module. > One of the conditions for doing that should > probably be that the code is fairly widely used and widely > required. Why? If the existing code could be better, why not improve it? > > Why not post it to an appropriate "recipe" page in the fledgling > Agile Control Forum site instead? (http://www.engcorp.com/acf) > That way others who *do* work in the machine control field will > have an early chance to try out your code, experiment, maybe > even improve it, fix bugs, Oh, there will be no bugs. > and basically do some of the work that > *should* be done before anything gets into the main Python distro... > I will give it a look. I had some spare time last year when I volunteered the first time. I don't have spare time now, and probably will not have before May at the earliest.. If someone would like to take over the code, I would be happy to contribute it and give as much help as I can. Jive -- http://mail.python.org/mailman/listinfo/python-list
Re: A lock that times out but doesn't poll
Dang. I forgot the line-wrap again. Sorry about that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing words from strings except 'and' / 'or' / 'and not'
Skip Montanaro <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > >> > Is there a reason to use sets here? I think lists will do as well. > >> > >> Sets are implemented using dictionaries, so the "if w in KEYWORDS" > >> part would be O(1) instead of O(n) as with lists... > >> > >> (I.e. searching a list is a brute-force operation, whereas > >> sets are not.) > > Jp> And yet... using sets here is slower in every possible case: > ... > Jp> This is a pretty clear example of premature optimization. > > I think the set concept is correct. The keywords of interest are best > thought of as an unordered collection. Lists imply some ordering (or at > least that potential). Premature optimization would have been realizing > that scanning a short list of strings was faster than testing for set > membership and choosing to use lists instead of sets. > > Skip Jp scores extra points for pre-maturity by not trying out version 2.4, by not reading the bit about sets now being built-in, based on dicts, dicts being one of the timbot's optimise-the-snot-out-of targets ... herewith some results from a box with a 1.4Ghz Athlon chip running Windows 2000: C:\junk>\python24\python \python24\lib\timeit.py -s "from sets import Set; x = Set(['and', 'or', 'not'])" "None in x" 100 loops, best of 3: 1.81 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "from sets import Set; x = Set(['and', 'or', 'not'])" "None in x" 100 loops, best of 3: 1.77 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = set(['and', 'or', 'not'])" "None in x" 100 loops, best of 3: 0.29 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = set(['and', 'or', 'not'])" "None in x" 100 loops, best of 3: 0.289 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = ['and', 'or', 'not']" "None in x" 100 loops, best of 3: 0.804 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = ['and', 'or', 'not']" "None in x" 100 loops, best of 3: 0.81 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "from sets import Set; x = Set(['and', 'or', 'not'])" "'and' in x" 100 loops, best of 3: 1.69 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = set(['and', 'or', 'not'])" "'and' in x" 100 loops, best of 3: 0.243 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = set(['and', 'or', 'not'])" "'and' in x" 100 loops, best of 3: 0.245 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = ['and', 'or', 'not']" "'and' in x" 100 loops, best of 3: 0.22 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = ['and', 'or', 'not']" "'and' in x" 100 loops, best of 3: 0.22 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = set(['and', 'or', 'not'])" "'not' in x" 100 loops, best of 3: 0.257 usec per loop C:\junk>\python24\python \python24\lib\timeit.py -s "x = ['and', 'or', 'not']" "'not' in x" 100 loops, best of 3: 0.34 usec per loop tee hee ... -- http://mail.python.org/mailman/listinfo/python-list
Michel MARTIN/GAUMONT est absent.
Je serai absent(e) du 28/06/2004 au 31/12/2004. A compter du 28/06/04 nouvelle adresse e mail: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: passing a socket to a spawned process.
Martin C.Atkins wrote: I have (finally!) put a package up on our website that provides a Python module for sending file descriptors down Unix-domain sockets, on Linux. See the first item under: http://www.mca-ltd.com/index.php?PAGE=resources/home.php Please let me know of any problems, obvious omissions, etc... BTW: I just found out about bindd (see the README), and could probably clean the code up from the examples in its sourcecode, but the current version of fdcred works for me! Sorry it has taken so long! I notice that you have used the LGPL for your code. Could you be convinced to use a Python style license? This would mean that some time in the (hopefully not too distant) future the code could be added to the standard socket module. - Dave -- http://www.object-craft.com.au -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing words from strings except 'and' / 'or' / 'and not'
On 28 Nov 2004 15:33:13 -0800, [EMAIL PROTECTED] (John Machin) wrote: >Skip Montanaro <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > > >> > Is there a reason to use sets here? I think lists will do as well. > > >> > > >> Sets are implemented using dictionaries, so the "if w in KEYWORDS" > > >> part would be O(1) instead of O(n) as with lists... > > >> > > >> (I.e. searching a list is a brute-force operation, whereas > > >> sets are not.) > > > > Jp> And yet... using sets here is slower in every possible case: > > ... > > Jp> This is a pretty clear example of premature optimization. > > > > I think the set concept is correct. The keywords of interest are best > > thought of as an unordered collection. Lists imply some ordering (or at > > least that potential). Premature optimization would have been realizing > > that scanning a short list of strings was faster than testing for set > > membership and choosing to use lists instead of sets. > > > > Skip > > Jp scores extra points for pre-maturity by not trying out version 2.4, > by not reading the bit about sets now being built-in, based on dicts, > dicts being one of the timbot's optimise-the-snot-out-of targets ... > herewith some results from a box with a 1.4Ghz Athlon chip running > Windows 2000: > > [snip - builtin `set' faster than sets.Set] John, Thanks for pointing out the existence of the new, built-in set type. I was well aware of it and the performance improvements it brings, but others may not have been. Since Python 2.4 hasn't actually be released yet, I don't think it could be of any help to the original poster, although I am well aware of the proclivity of a significant portion of the Python community to eagerly begin developing against pre-release versions of Python. Since the code I was claiming suffered from premature optimization didn't use the set type, I'm not sure of the relevance of this point. In fact, it is trivially _more_ work to convert from usage of sets.Set to usage of set than it is to convert from usage of lists to usage of set. If anything, the list version would have been easier to migrate, once 2.4 was a suitable deployment platform. As Skip pointed out, though, Sets can be seen as a conceptually better fit for the problem, so the performance or simplified migration of lists over set.Sets is hardly a justification for the use of lists. My post was intended solely to rebut the position that sets.Set would desirable because they were more efficient, as the poster to whom I was responding had claimed. I also tried to emphasize the fact that optimization is senseless without first identifying bottlenecks and that the function in question almost certainly was not even a blip on the performance radar of the program to which it belonged, but perhaps I was not sufficiently clear on that point. In any case, thanks for the points. I'll try to exchange them for some alms at the next town. :) Hope this resolves some confusion, Jp -- http://mail.python.org/mailman/listinfo/python-list
Re: The use of :
On Sun, 28 Nov 2004, [ISO-8859-1] BJörn Lindqvist wrote: > In the faq, > http://www.python.org/doc/faq/general.html#why-are-colons-required-for-the-if-while-def-class-statements, > it is stated that the colon is there "primarily to enhance readability > (one of the results of the experimental ABC language)." But can that > statement really be backed up? Has someone made a study or something? > I always thought the rule was "the less useless symbols, the higher > the readability." I.e: ... snip ... > IMHO, the colon-less variant is more readable than the one with the colon. And yet you use a colon above to indicate ownership of the following chunk of text - specifically ownership by the "I.e" to illustrate your point. Methinks there may be a connection between the assertions: * But I could be wrong :-) Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a consensus on how to check a polymorphic instance?
Peter Hansen <[EMAIL PROTECTED]> wrote: > > But the problem is still there: how do you know what > > it looks like before you treat it as a cat? isinstance(), , as Steve > > state, is too rigid. > > The argument is that you probably don't really need to know > what it looks like *before* you try to use it, even if you > think you do. The cases where you really do are probably those > Alex Martelli's recipe (mentioned near the start of the thread) > is intended to help. (Specifically, avoiding the situation > where the object implements the required protocol only partially, > but you don't find that out until you've already started using > the object, possibly corrupting it in the process.) Exactly. The recipe's still in the CB 2nd edition (which I should be editing right now instead of doing usenet, with deadline so terribly close and lots of enhancements left to do, but hey, it IS 1:30 AM, I deserve a little break;-). The right solution is adaptation (PEP 246, Eby's PyProtocols, etc), but until we can convince Guido of that, so that adaptation becomes widespread, duck typing, and occasionally (when needed) "accurate LBYL" remain the best approach. And don't forget unit-tests -- see Robert Martin's now-famous article at http://www.artima.com/weblogs/viewpost.jsp?thread=4639 . Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a consensus on how to check a polymorphic instance?
Dan Perl <[EMAIL PROTECTED]> wrote: > I have a question here, as we are discussing now protocol interfaces vs. > inheritance. Is using a class that implements a protocol without inheriting > from a base class still "polymorphism"? ``still'' is inappropriate here. It is _fully_ polymorphism, of course. It's known as signature-based polymorphism. C++ has it in templates, only, where it's the basis of the whole power of the standard library containers, algorithms, iterators, etc. Python has it everywhere, except where some coder breaks everything with 'isinstance' or the like. > There are probably many definitions > for polymorphism and probably all those definitions can be interpreted in > such a way that they accept also protocols. But what I would like to hear Otherwise they're very broken and useless definitions. > is what is the general opinion of people who use python. I am biased > because I come from a C++ and Java background and I am still used to a > certain practical meaning for "polymorphism". One that doesn't apply to C++ templates?! > But it's beginning to dawn on > me that it is only a bias and polymorphism does apply also to python > protocol interfaces. Is that generally accepted? Yep. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: protocols, inheritance and polymorphism
Christophe Cavalaria <[EMAIL PROTECTED]> wrote: > If your programs need that much dynamic_cast to work, then your programs are > bad. Wrong. Look at the absolute mess that the Visitor design pattern is, and how Robert Martin made it much less horrible by turning it into Dynamic Visitor -- which needs so much dynamic_cast it hurts. In Java, you're dynamic_cast'ing all of the time in a totally obscure way, each time you're pulling stuff out of a containter. SomeSillyType foo = (SomeSillyType) (mycontainer.getsomething()); since the container's method returns Object, the cast is dynamic -- only checked at runtime. C++, and the latest Java, give up OO in favour of another paradigm (generic programming) to deal with this, and if this isn't an admission that their "static" (ha!) typesystem doesn't work with OOP properly, I don't know what would count as one. > Besides, it's easy to do a 'safe' dynamic_cast, just assert that the > pointer you get isn't 0 after the cast. or catch the dynamically generated exception in Java's case, sure. You can "easily" implement what a decent language would have in the first place... except that co-variance and counter-variance continue to dog every effort to make a decent "static OOP typesystem", of course...:-) Alex -- http://mail.python.org/mailman/listinfo/python-list
Closing files
I have recently started playing around with Python. Some of the things I have done have involved reading files. The way I do this is along the lines of f = file('file.txt') lines = f.readlines() f.close() I have noticed that it is possible to do this in one line: lines = file('file.txt').readlines() My question is: does the file get closed if I do the reading in this manner? Similarly, for reading the output from other programs or system commands, I would do: o = popen('executable') lines = o.readlines() o.close() Is it OK to do this with a one-liner as well, with lines = popen('executable').readlines() without closing the file object? Thanks, Henrik Holm -- http://mail.python.org/mailman/listinfo/python-list
Re: Closing files
On Sun, 28 Nov 2004 18:59:31 -0600, [EMAIL PROTECTED] (Henrik Holm) wrote: >I have recently started playing around with Python. Some of the things > I have done have involved reading files. The way I do this is along the > lines of > > [snip] http://www.google.com/search?q=site%3Amail.python.org+file+closing Jp -- http://mail.python.org/mailman/listinfo/python-list
Re: Closing files
[EMAIL PROTECTED] (Henrik Holm) writes: [+] > I have recently started playing around with Python. Some of the things > I have done have involved reading files. The way I do this is along the > lines of > > f = file('file.txt') > lines = f.readlines() > f.close() Verbose and readable. A typical approach. [+] > > I have noticed that it is possible to do this in one line: > > lines = file('file.txt').readlines() > > My question is: does the file get closed if I do the reading in this > manner? It appears to be closed on my Linux system as by using this shorthand approach, you are not saving any reference to the file object. Evidently, it is closed immediatly after the statement executes. There's no point in the file staying open as you'd have no way to refer to it any more. [+] > > Similarly, for reading the output from other programs or system > commands, I would do: > > o = popen('executable') > lines = o.readlines() > o.close() > > Is it OK to do this with a one-liner as well, with > > lines = popen('executable').readlines() My guess is that this is probably OK too. At least for simple cases. My experience has been, that by going for maximum terseness, you eventually get into trouble somehow. YMMV [+] > > without closing the file object? If you are going to have one or more references to the file or pipe object, you must either close them or delete the reference to the object using del(). If you are running on Unix, do some experimentation with the 'fuser' or 'lsof' commands to see if the system is reporting the files open or closed. Or why not for fun; while True: file('/tmp/foo') I bet this runs forever and you don't run out of open file descriptors :-) [+] > > Thanks, > Henrik Holm -- --- Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant 305 321-1144 (mobilehttp://www.JerrySievers.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: The use of :
Jeremy Bowers wrote: The only punctuation you *need* is whitespace. See Forth You don't even need that... see FORTRAN. :-) DOI=1TO10-ly, -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg -- http://mail.python.org/mailman/listinfo/python-list
Re: The use of :
> "Greg" == Greg Ewing <[EMAIL PROTECTED]> writes: >> The only punctuation you *need* is whitespace. See Forth Greg> You don't even need that... see FORTRAN. :-) And you don't need everything else either... see this. http://compsoc.dur.ac.uk/whitespace/ :-) Regards, Isaac. -- http://mail.python.org/mailman/listinfo/python-list
Re: The use of :
A two-fer. On Mon, 29 Nov 2004 10:28:42 +0800, Isaac To wrote: >> "Greg" == Greg Ewing <[EMAIL PROTECTED]> writes: > > >> The only punctuation you *need* is whitespace. See Forth > > Greg> You don't even need that... see FORTRAN. :-) Well, I for one don't like reading large programs with no line feeds :-) > And you don't need everything else either... see this. > > http://compsoc.dur.ac.uk/whitespace/ I'm pretty sure if you remove all the whitespace and you remove all the non-whitespace that you have indeed gotten a little too minimal :-) -- http://mail.python.org/mailman/listinfo/python-list
Help on creating a HTML by python
Can anyone help me to use a python to create an HTML photo gallery generator. When it's finished, it will be able find all the picture files (i.e. .jpg, .gif. .png files) in any given folder on the computer, automatically create smaller thumbnails for each image, and then generate a complete HTML file that displays a clickable image gallery. When viewed in a web browser, the HTML file will display the thumbnails in a neatly formatted table, and if you click on one of the thumbnails the full-size image will appear. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: graphics
You'll need wxPython. Once you get that, look in the samples for pySketch. This is a very straightforward program that helped me learn a lot about GUI with wxPython. Pretty easy to do. Once you get a hang for the basics, then you might be interested in wxGlade, an interactive GUI designer. wxGlade is more advanced than you need for your request. -- http://mail.python.org/mailman/listinfo/python-list
Re: network programming without goto
kent sin <[EMAIL PROTECTED]> wrote: > > But that will make too many uncessary connection: > >one connection can do a number of search before it > got timeout, so I want to do as many search as > possible before it got timeout. I think the connection > cost is high here, and it also got some load on the > remote servers which I do not want. > > Thanks for the suggestion. Indeed it will do many connections, but you weren't terribly specific with what you wanted. In any case, if you want a total of 3 failures under any situation, try the following. queries = [buildquery(t) for t in targets] tries = 3 for host in hostlist: q = iter(queries) try: cq = q.next() except StopIteration: continue for i in xrange(tries): conn = zoom.Connecton(host.ip, host.port) fail = 0 while 1: try: r = conn.query(cq) #deal with r cq = q.next() except StopIteration: break except: fail = 1 break if not fail: break try: conn.close() except: pass - Josiah > > --- Josiah Carlson <[EMAIL PROTECTED]> wrote: > > > > > kent sin <[EMAIL PROTECTED]> wrote: > > > > > > Please help: > > > > > > I was really blocked here. without goto I really > > do > > > not known how to do it. > > > > > > The problem is to use PyZ3950 to consult a lists > > of > > > hosts and for each of them to search for a list of > > > targets. Since the network is undetermined, there > > were > > > always some exceptions: I would like to allow it > > to > > > retry for 3 times. Moreover, during the query > > process, > > > the conn will timeout (set by the remote server). > > > Reconnect is preferred before fail the current > > search, > > > but the reconnect may fail even if the first try > > is > > > succeed. > > > > The trick with getting it to do what you want it to > > do is to understand > > what you want it to do. > > > > Being that I can't understand what you want it to > > do, the following is > > just an interpretation of what I think you want it > > to do. If you want > > it to do something different, then be clearer with > > what you want it to > > do and ask again. Note that depending on the > > semantics of your > > connection, this could probably be made more > > efficient. > > > > > > queries = [buildquery(t) for t in targets] > > > > for host in hostlist: > > tries_remaining = 3 #tunable parameter > > for q in queries: > > for i in xrange(tries_remaining+1): > > if i == tries_remaining: > > break > > try: > > conn = zoom.Connecton(host.ip, > > host.port) > > r = conn.search(q) > > conn.close() > > break > > except: > > continue > > > > #handle result r > > break > > > > tries_remaining -= i > > > > if tries_remaining == 0: > > break > > > > - Josiah > > > > -- http://mail.python.org/mailman/listinfo/python-list
how to drop all thread ??
if class A( use threading,thread module ) to produce 100 thread,how to drop its (100 thread) when its running -- http://mail.python.org/mailman/listinfo/python-list
Building web graphics with Python
I am wondering if there is a light weight Python library for producing web graphics on-the-fly. There is a C-language library called gd that can be used in a CGI program to produce gif images. The Library can be used to produce graphics images that are dynamically generated. I was wondering if there is something similar for Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal printing without the exponent
"Bryan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > is there a way to make the Decimal class not print the exponent version of the > decimal? > > > >>> str(Decimal('1010')) > '1010' > >>> str(Decimal((0, (1, 0, 1), 1))) > '1.01E+3' > >>> > > how do you make the 2nd example print 1010? The quantize method will convert to any desired exponent (zero in your example): >>> d = (Decimal((0, (1, 0, 1), 1))) >>> d Decimal("1.01E+3") >>> d.quantize(Decimal(1)) Decimal("1010") Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list
Standalone email package 3.0 final
Python 2.4 final will probably be released in a few hours so this seems like a good time to release the standalone email package, version 3.0 final. Unless there's some last second snafu, this will be identical to the version released with Python 2.4. email 3.0 is compatible with Python 2.3 and 2.4. If you need to support earlier versions of Python, stick with email 2.5.5. For documentation (until Fred flips the "current" docs switch) and download links, please see the email-sig home page: http://www.python.org/sigs/email-sig Changes in email 3.0 include: * New FeedParser provides an incremental parsing API for applications that may need to read email messages from blocking sources (e.g. sockets). FeedParser is also more standards compliant than the old parser and is "non-strict", so that it should never raise parse errors when parsing broken messages. * The old Parser API is (mostly) supported for backward compatibility. * Previously deprecated API features have been removed, while a few more deprecations have been added. * Support for Pythons earlier than 2.3 have been removed. * Lots and lots of fixes. Feel free to join the email-sig mailing list for further discussion. -Barry signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: The use of :
On Mon, 29 Nov 2004 01:12:16 -0500, Jeremy Bowers wrote: > The only punctuation you *need* is whitespace. See Forth (I don't know > if this is perfect but I'd bet the transform is simple), : Announce ." Forth has a fair bit of punctuation" ; -- http://mail.python.org/mailman/listinfo/python-list
Re: wxStyledTextCtrl problem ?
Paul Robson <[EMAIL PROTECTED]> wrote: > > I have a wierd thing with a little editor app I'm writing. > > I'm using wxStyledTextCtrl ; the wrapper for Scintilla. When I create the > frame in wxPython, I use self.Editor.SetFocus() to put the focus initially > on the editor. > > This works fine. > > Odd thing is though, switching back and forwards between applications > alternately hides and reappears the caret. > > Hit Alt-Tab twice and it disappears > Hit Alt-Tab twice and it comes back. > > It still works fine - there's just no caret. I've tried various things in > EVT_ACTIVATE including Moving the Caret on screen, and forcing it to be > visible - they are being called but it makes no difference. > > Any ideas ? I don't know why the problem you are having happens, but I would just make a call to self.Editor.SetFocus() on an EVT_ACTIVATE event. - Josiah -- http://mail.python.org/mailman/listinfo/python-list