Re: Create a class to position a window on the screen.

2011-01-10 Thread Zac Burns
I'm not exactly sure what you are asking here, but one problem that is notable in your example is that the center function is indented inside the __init__ function. This would create a closure instead of a method on PositionWindow, which is probably not what you want. -Zac On Sun, Jan 9, 2011 a

Re: shelf-like list?

2010-08-14 Thread Zac Burns
This should help: http://docs.python.org/library/pickle.html -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer Zindagi Games On Sat, Aug 14, 2010 at 5:13 PM, kj wrote: > In > Raymond Hettinger writes: > > >On Aug 12, 1:37=A0pm, Thomas Jollans wrote: > >> On Tuesday 10 Augus

Extract stack from running python program

2010-08-12 Thread Zac Burns
Is there a utility to extract the stacks from a running python program that is hung? Sounds like a long shot but if anyone knows it would be you guys. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer Zindagi Games -- http://mail.python.org/mailman/listinfo/python-list

Re: Lockless algorithms in python (Nothing to do with GIL)

2010-07-06 Thread Zac Burns
k()', 'from threading import Lock') 1.4162585386092708 >>> timeit.timeit('dict()', 'from threading import Lock') 0.2730348901369162 >>> timeit.timeit('list()', 'from threading import Lock') 0.1719480219512306 -Zac On Fri, Jul 2, 2

Re: Lockless algorithms in python (Nothing to do with GIL)

2010-06-28 Thread Zac Burns
> > Sure, but I think you're timing the wrong thing here. You would only > allocate the lock relatively rarely - it's the overhead of *acquiring* > the lock that's the real problem. > > r...@durian:~$ python -m timeit -s "from threading import Lock; l = > Lock()" "l.acquire(); l.release()" > 1

Lockless algorithms in python (Nothing to do with GIL)

2010-06-28 Thread Zac Burns
In my experience it is far more expensive to allocate a lock in python then it is the types that use them. Here are some examples: >>> timeit.timeit('Lock()', 'from threading import Lock') 1.4449114807669048 >>> timeit.timeit('dict()') 0.2821554294221187 >>> timeit.timeit('list()') 0.17358153222

Strange factory pattern

2010-06-22 Thread Zac Burns
In the threading module there are several code bits following this convention: ### def Class(*args, **kwargs): return _Class(*args, **kwargs) class _Class(... ### This is true for Event, RLock, and others. Why do this? It seems to violate the rule of least astonishment (isinstance(Event(),

Re: Traceback spoofing

2010-05-21 Thread Zac Burns
> Except you can't re-raise them. > Yes, I should have noted that in the original post: >>> raise RuntimeError, 'X', wrapped_traceback Traceback (most recent call last): File "", line 1, in TypeError: raise: arg 3 must be a traceback or None Does someone know where the thread went about it b

Traceback spoofing

2010-05-21 Thread Zac Burns
Why can't I inherit from traceback to 'spoof' tracebacks? I would like to create a traceback that is save-able to re-raise exceptions later without leaking all the locals. (I'm sure this idea has been discussed before but I can't find it anymore.) class Traceback(types.TracebackType): pass TypeErr

Re: [PyQt] Carol Newman

2010-04-20 Thread Zac Burns
Yes, please do not remove me. Sorry for the inconvenience! -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer Zindagi Games On Tue, Apr 20, 2010 at 3:36 PM, Chris Kaynor wrote: > There was a G-mail invasion earlier today that allowed e-mails to be sent > from any g-mail account wi

Carol Newman

2010-04-20 Thread Zac Burns
http://www.ristorantealpirata.com/home.php -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer Zindagi Games -- http://mail.python.org/mailman/listinfo/python-list

Re: lib2to3 pattern creation with unexpected results

2009-12-22 Thread Zac Burns
On Tue, Dec 22, 2009 at 3:21 PM, Benjamin Peterson wrote: > > The pattern for that is funcdef< 'def' 'singleLineFunc' parameters< '(' ')' > > > ':' simple_stmt< return_stmt< 'return' arith_expr< '1' '+' '2' > > '\n' > > >. No > suite. > > I'm trying to match any function block, the two examples we

lib2to3 pattern creation with unexpected results

2009-12-22 Thread Zac Burns
Greetings, I'm trying to re-purpose the lib2to3 module and along the way came up with this pattern: "funcdef<'def' name=NAME parameters ['->' test] ':' suite=suite>" It seems to have 2 problems: 1. Single-line defs are not matched. Eg: "def singleLineFunc(): return 1 + 2" is not matched,

Re: Python (and me) getting confused finding keys

2009-12-22 Thread Zac Burns
On Tue, Dec 22, 2009 at 8:56 AM, John wrote: > > another thread can remove the key prior to the has_key call; or perhaps > > edges isn't a real dictionary? > > > > of course. But unless there is a way of using threading without being aware > of > it, this is not the case. Also, edges is definite

__import__ returns module without it's attributes?

2009-11-13 Thread Zac Burns
I've overloaded __import__ to modify modules after they are imported... but running dir(module) on the result only returns __builtins__, __doc__, __file__, __name__, __package__, and __path__. Why is this? More importantly, where can I hook in that would allow me to see the contents of the module?

Re: Threaded import hang in cPickle.dumps

2009-11-11 Thread Zac Burns
On Tue, Nov 10, 2009 at 2:27 PM, Benjamin Peterson wrote: > Zac Burns gmail.com> writes: >> What can I do about this? > > Not run it in a thread. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > Isn't requesting that pickle not be use

Re: Threaded import hang in cPickle.dumps

2009-11-10 Thread Zac Burns
Oh, I'm pickling an NotImplementedError and it's importing exceptions. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Tue, Nov 10, 2009 at 10:50 AM, Zac Burns wrote: > Using python 2.6 > > cPickle.dumps has an import

Threaded import hang in cPickle.dumps

2009-11-10 Thread Zac Burns
Using python 2.6 cPickle.dumps has an import which is causing my application to hang. (figured out by overriding builtin.__import__ with a print and seeing that this is the last line of code being run. I'm running cPickle.dumps in a thread, which leads me to believe that the first restriction here

Re: unittest wart/bug for assertNotEqual

2009-10-20 Thread Zac Burns
> I was with you right up to the last six words. > > Whether it's worth changing assertNotEqual to be something other than an > alias of failIfEqual is an interesting question. Currently all the > assert* and fail* variants are aliases of each other, which is easy to > learn. This would introduce a

unittest wart/bug for assertNotEqual

2009-10-20 Thread Zac Burns
Using the assertNotEqual method of UnitTest (synonym for failIfEqual) only checks if first == second, but does not include not (first != second) According to the docs: http://docs.python.org/reference/datamodel.html#specialnames There are no implied relationships among the comparison operators. Th

Why is python so sad?

2009-10-14 Thread Zac Burns
There are 10741 occurences of ): or :( in our source code and only 2 occurrences of :) or (:. Not what you would expect from a language named after a comedian. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games -- http://mail.python.org/mailman/list

Work around metaclass programming

2009-10-12 Thread Zac Burns
I have a class called Signal which is a descriptor. It is a descriptor so that it can create BoundSignals, much like the way methods work. What I would like to do is to have the class be a descriptor when instantiated in what will be the locals of the class, but not a descriptor everywhere else. C

Re: Doubley imported module caused devastating bug

2009-09-24 Thread Zac Burns
On Thu, Sep 24, 2009 at 1:38 PM, Carl Banks wrote: > On Sep 24, 10:26 am, Zac Burns wrote: >> Currently it is possible to import a file of one path to more than one >> 'instance' of a module. One notable example is "import __init__" from >> a package.

Doubley imported module caused devastating bug

2009-09-24 Thread Zac Burns
Currently it is possible to import a file of one path to more than one 'instance' of a module. One notable example is "import __init__" from a package. See http://stackoverflow.com/questions/436497/python-import-the-containing-package This recently caused a devastating bug in some of my code. Wha

Re: socket send O(N**2) complexity

2009-09-21 Thread Zac Burns
On Mon, Sep 21, 2009 at 2:10 PM, Rob Williscroft wrote: >  wrote in news:mailman.216.1253565002.2807.python-l...@python.org in > comp.lang.python: > >>>Niether of the CPython versions (2.5 and 3.0 (with modified code)) >>>exibited any memory increase between "allocated 1 meg + " and "end" >> >> Yo

socket send O(N**2) complexity

2009-09-21 Thread Zac Burns
The mysocket.mysend method given at http://docs.python.org/howto/sockets.html has an (unwitting?) O(N**2) complexity for long msg due to the string slicing. I've been looking for a way to optimize this, but aside from a pure python 'string slice view' that looks at the original string I can't thin

Re: Python server locks up

2009-09-10 Thread Zac Burns
On Wed, Sep 9, 2009 at 6:52 PM, David Stanek wrote: > On Wed, Sep 9, 2009 at 4:28 PM, Zac Burns wrote: >> >> How would you suggest to figure out what is the problem? >> > > I don't think you said your OS so I'll assume Linux. > > Sometimes it is more noi

Re: Python server locks up

2009-09-09 Thread Zac Burns
> If it has been running continuously all that time then it might be that > the dictionary has grown too big (is that possible?) or that it's a > memory fragmentation problem. In the latter case it might be an idea to > restart Python every so often; perhaps it could do that automatically > during

Python server locks up

2009-09-09 Thread Zac Burns
I have a server running Python 2.6x64 which after running for about a month decides to lock up and become unresponsive to all threads for several minutes at a time. While it is locked up Python proceeds to consume large amounts of continually increasing memory. The basic function of the server is

Re: Why all the __double_underscored_vars__?

2009-08-08 Thread Zac Burns
As I understand it, the double underscores is to create a namespace "reserved for python's internal use". That way python can add more variables and methods in the future and as long as people respect the namespace their code will not break with future revisions. -- Zachary Burns (407)590-4814 Aim

Retrieving a partial pickle

2009-07-17 Thread Zac Burns
I have a large pickle file, which happens to be a list with lots of objects in it. What sort of things can I do without unpickling the whole object? I would particularly like to retrieve one of the elements in the list without unpicking the whole object. If the answer is not specific to lists th

Self optimizing iterable

2009-07-17 Thread Zac Burns
Greetings, I would like a set like object that when iterated maintains a count of where iteration stopped and then re-orders itself based on that count so that the iteration stopped on the most bubble to the top. An example use case for this would be for something like a large table of regular ex

Re: psyco V2 beta2 benchmark

2009-07-09 Thread Zac Burns
Where do you get this beta? I heard that Psyco V2 is coming out but can't find anything on their site to support this. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Sat, Jul 4, 2009 at 5:26 AM, larudwer wrote: > just out of curiosity i've

Re: __file__ access extremely slow

2009-06-06 Thread Zac Burns
I think I have figured this out, thanks for your input. The time comes from lazy modules related to e-mail importing on attribute access, which is acceptable. Hence of course why ImportError was sometime raised. I originally was thinking that accessing __file__ was triggering some mechanism that

Re: __file__ access extremely slow

2009-06-04 Thread Zac Burns
-- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jun 4, 2009 at 6:24 PM, Zac Burns wrote: > The section of code below, which simply gets the __file__ attribute of > the imported modules, takes more than 1/3 of the total startu

__file__ access extremely slow

2009-06-04 Thread Zac Burns
The section of code below, which simply gets the __file__ attribute of the imported modules, takes more than 1/3 of the total startup time. Given that many modules are complicated and even have dynamic population this figure seems very high to me. it would seem very high if one just considered the

Cannot start a thread in atexit callback

2009-05-05 Thread Zac Burns
It seems that one cannot start a thread in an atexit callback. My use case is that I have a IO heavy callback that I want to run in a thread so that other callbacks can finish while it's doing it's thing to save on exit time. Example code (py3k) import

Re: Return value usage

2009-04-29 Thread Zac Burns
> The point of caching is that it lets you retrieve a result cheaply that > was expensive to produce by saving the result in case it's needed again. > If the caching itself is expensive because it requires network access > then, IMHO, that's not proper caching! (You would need a 2-level cache, > ie

Re: Return value usage

2009-04-29 Thread Zac Burns
On Wed, Apr 29, 2009 at 10:14 AM, Simon Brunning wrote: > 2009/4/29 Zac Burns : > Why not return a proxy, and have the proxy do the retrieval of the > needed data if it's used? Delegation is ridiculously easy in Python. Interesting idea. I like it. I've looked through som

Return value usage

2009-04-29 Thread Zac Burns
I would like to know when my function is called whether or not the return value is used. Is this doable in python? If it is, can it ever be pythonic? The use case is that I have functions who's side effects and return values are cached. I would like to optimize them such that I don't have to recal

Re: python needs leaning stuff from other language

2009-04-02 Thread Zac Burns
Is it really worth it to not implement list.clear and answer this question over and over again? I see no reason that a list shouldn't have a .clear method. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Apr 2, 2009 at 5:32 PM, Esmail

Re: Executing global code

2009-01-15 Thread Zac Burns
I'm not sure I fully understand the question "no moving the code to a function", but you can prevent reload in a module by doing something like this: doLoad = False try: no_reload except NameError: no_reload = True else: raise RuntimeError, "This module is not meant to be reloaded." -- Zach

Re: Executing global code

2009-01-15 Thread Zac Burns
The first line: doLoad = False, is to be ignored. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 15, 2009 at 10:30 AM, Zac Burns wrote: > I'm not sure I fully understand the question "no moving the code to a > fu

Re: Making a decorator a staticmethod

2009-01-08 Thread Zac Burns
256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 12:21 PM, Bruno Desthuilliers wrote: > Jonathan Gardner a écrit : >> >> On Jan 8, 11:18 am, "Zac Burns" wrote: >>> >>> In my use case (not the example below) the decorator ret

Re: cPickle vs pickle discrepancy

2009-01-08 Thread Zac Burns
8, 12:27 pm, "Zac Burns" wrote: >> Thanks for your patience waiting for me to isolate the problem. >> >> | Package >> --__init__.py ->empty >> --Package.py ->empty >> --Module.py >> import cPickle >> class C(object): >

Re: Making a decorator a staticmethod

2009-01-08 Thread Zac Burns
ns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Jan 8, 2009 at 10:54 AM, Zac Burns wrote: > I have a decorator in a class to be used by that class and by inheriting > classes > > ## > class C(object): >@staticmethod # With

Making a decorator a staticmethod

2009-01-08 Thread Zac Burns
I have a decorator in a class to be used by that class and by inheriting classes ## class C(object): @staticmethod # With this line enabled or disabled usage in either C or D will be broken. To see that D works remember to remove usage in C def decorateTest(func):

Re: cPickle vs pickle discrepancy

2009-01-08 Thread Zac Burns
le and Module.py contained support code for the package. -Zac -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Tue, Jan 6, 2009 at 4:57 PM, Gabriel Genellina wrote: > En Mon, 05 Jan 2009 23:04:30 -0200, Zac Burns escribió: > >> I

cPickle vs pickle discrepancy

2009-01-05 Thread Zac Burns
Greetings, I have a module that attempts to pickle classes defined in that module. I get an error of the form: PicklingError: Can't pickle : import of module Module.SubModule failed when using cPickle (protocol -1, python version 2.5.1). The module has already been imported and is in sys.modules

Re: Overriding a method at the instance level on a subclass of a builtin type

2008-12-04 Thread Zac Burns
Ok. Feature request then - assignment of a special method name to an instance raises an error. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Dec 4, 2008 at 10:13 AM, George Sakkis <[EMAIL PROTECTED]> wrote: > On Dec 4, 1:03

Re: Overriding a method at the instance level on a subclass of a builtin type

2008-12-04 Thread Zac Burns
CTED]> wrote: >> "Zac Burns" <[EMAIL PROTECTED]> writes: >> > The class method seems to be the most promising, however I have more >> > 'state' methods to worry about so I might end up building new classes >> > on the fly rather than have

Re: Overriding a method at the instance level on a subclass of a builtin type

2008-12-04 Thread Zac Burns
The class method seems to be the most promising, however I have more 'state' methods to worry about so I might end up building new classes on the fly rather than have a class per permutation of states! Now the code isn't quite as clear as I thought it was going to be. It seems unfortunate to me th

Re: Reverse zip() ?

2008-12-02 Thread Zac Burns
More succinct failure: keys, values = zip(*{}.iteritems()) -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Tue, Dec 2, 2008 at 4:47 PM, Zac Burns <[EMAIL PROTECTED]> wrote: > There is a problem with this however, which promp

Overriding a method at the instance level on a subclass of a builtin type

2008-12-02 Thread Zac Burns
Sorry for the long subject. I'm trying to create a subclass dictionary that runs extra init code on the first __getitem__ call. However, the performance of __getitem__ is quite important - so I'm trying in the subclassed __getitem__ method to first run some code and then patch in the original dict

Re: Reverse zip() ?

2008-12-02 Thread Zac Burns
There is a problem with this however, which prompted me to actually write an unzip function. One might expect to be able to do something like so (pseudocode)... def filesAndAttributes(): files = walk() attributes = [attr(f) for f in files] return zip(files, attributes) files, attributes

marshal locks program even in thread

2008-11-07 Thread Zac Burns
Greetings, It seems that marshal.load will lock the problem if the file object (in this case a pipe) is not ready to be read from - even if it's done in a thread. The use case here is in writing a scripting interface for perforce using the -G option (http://www.perforce.com/perforce/doc.072/manua

Re: Dictionary membership check failure

2008-11-05 Thread Zac Burns
an equivalency check of some sort (I don't know the C code, this is an educated guess) without ever hashing so it succeeded. -- Zachary Burns Aim - Zac256FL Production Engineer Zindagi Games On Wed, Nov 5, 2008 at 11:34 AM, Zac Burns <[EMAIL PROTECTED]> wrote: > Greetings

Dictionary membership check failure

2008-11-05 Thread Zac Burns
Greetings, I have a dictionary that seems to be misbehaving on a membership check. This test code: 1: import types 2: assert myDict.__class__ is types.DictionaryType 3: assert (key in myDict.keys()) == (key in myDict) raises AssertionError on line three. The dictionary items are all of type (str