Re: WeakValueDict and threadsafety

2011-12-10 Thread Darren Dale
On Dec 10, 2:09 pm, Duncan Booth wrote: > Darren Dale wrote: > > On Dec 10, 11:19 am, Duncan Booth > > wrote: > >> Darren Dale wrote: > > def get_data(oid): > >     with reglock: > >         data = registry.get(oid, None) > >         if da

Re: WeakValueDict and threadsafety

2011-12-10 Thread Darren Dale
On Dec 10, 11:19 am, Duncan Booth wrote: > Darren Dale wrote: > > I'm concerned that this is not actually thread-safe. When I no longer > > hold strong references to an instance of data, at some point the > > garbage collector will kick in and remove that entry from

WeakValueDict and threadsafety

2011-12-10 Thread Darren Dale
I am using a WeakValueDict in a way that is nearly identical to the example at the end of http://docs.python.org/library/weakref.html?highlight=weakref#example , where "an application can use objects IDs to retrieve objects that it has seen before. The IDs of the objects can then be used in other

multiprocessing in subpackage on windows

2011-04-20 Thread Darren Dale
I have two really simple scripts: C:\Python27\Scripts\foo --- if __name__ == '__main__': import bar bar.main() C:\Python27\Lib\site-packages\bar.py --- from multiprocessing import Pool def task(arg): return arg def main(): pool = Pool() res = pool.apply_async(task, (3.14,))

Re: two brief question about abstractproperty

2011-03-12 Thread Darren Dale
On Mar 12, 11:16 pm, Darren Dale wrote: > I've been reading PEP 3119 and the documentation for ABCs in the > python documentation. According to the PEP, the following should yield > an error, because the abstract property has not been overridden: > > import abc > class

two brief question about abstractproperty

2011-03-12 Thread Darren Dale
I've been reading PEP 3119 and the documentation for ABCs in the python documentation. According to the PEP, the following should yield an error, because the abstract property has not been overridden: import abc class C: __metaclass__ = abc.ABCMeta @abc.abstractproperty def x(self):

possible circular import problem with python-3, but not python-2

2010-09-27 Thread Darren Dale
I am attempting to contribute to the h5py project by porting the code for python-3. The code is available in a branch at github: http://github.com/darrendale/h5py/tree/py3k . That code uses cython to wrap the hdf5 library. So far, only a few minor changes have been needed (relative imports, change

Re: problem with simple multiprocessing script on OS X

2010-08-25 Thread Darren Dale
On Aug 24, 4:32 pm, Thomas Jollans wrote: > On Tuesday 24 August 2010, it occurred to Darren Dale to exclaim: > > > > > > > On Aug 23, 9:58 am, Darren Dale wrote: > > > The following script runs without problems on Ubuntu and Windows 7. > > > h5py is

Re: problem with simple multiprocessing script on OS X

2010-08-25 Thread Darren Dale
On Aug 24, 4:32 pm, Thomas Jollans wrote: > On Tuesday 24 August 2010, it occurred to Darren Dale to exclaim: > > > > > > > On Aug 23, 9:58 am, Darren Dale wrote: > > > The following script runs without problems on Ubuntu and Windows 7. > > > h5py is

Re: problem with simple multiprocessing script on OS X

2010-08-25 Thread Darren Dale
On Aug 24, 5:29 pm, Benjamin Kaplan wrote: > On Tue, Aug 24, 2010 at 3:31 PM, Darren Dale wrote: > > On Aug 23, 9:58 am, Darren Dale wrote: > >> The following script runs without problems on Ubuntu and Windows 7. > >> h5py is a package wrapping the hdf5 librar

Re: problem with simple multiprocessing script on OS X

2010-08-24 Thread Darren Dale
On Aug 23, 9:58 am, Darren Dale wrote: > The following script runs without problems on Ubuntu and Windows 7. > h5py is a package wrapping the hdf5 library (http://code.google.com/p/ > h5py/): > > from multiprocessing import Pool > import h5py > > def update(i): &

problem with simple multiprocessing script on OS X

2010-08-23 Thread Darren Dale
The following script runs without problems on Ubuntu and Windows 7. h5py is a package wrapping the hdf5 library (http://code.google.com/p/ h5py/): from multiprocessing import Pool import h5py def update(i): print i def f(i): "hello foo" return i*i if __name__ == '__main__': pool

Re: Is it possible to use keyword arguments from C?

2009-07-13 Thread Darren Dale
On Jul 13, 9:38 am, Darren Dale wrote: > I am learning about the python C-api in order to contribute a feature > to numpy. I see a discussion (http://docs.python.org/extending/ > extending.html#keyword-parameters-for-extension-functions) on how to > create a function or method  in C

Is it possible to use keyword arguments from C?

2009-07-13 Thread Darren Dale
I am learning about the python C-api in order to contribute a feature to numpy. I see a discussion (http://docs.python.org/extending/ extending.html#keyword-parameters-for-extension-functions) on how to create a function or method in C that accepts kwargs, but is it possible to call such a method

Re: design question, metaclasses?

2009-04-12 Thread Darren Dale
On Apr 12, 4:50 pm, Kay Schluehr wrote: > On 11 Apr., 20:15, Darren Dale wrote: > > > I am working on a project that provides a high level interface to hdf5 > > files by implementing a thin wrapper around h5py. > > I would like to > > generalize the project so the s

Re: design question, metaclasses?

2009-04-12 Thread Darren Dale
On Apr 12, 3:23 pm, Aaron Brady wrote: > On Apr 12, 1:30 pm, Darren Dale wrote: > > > > > On Apr 11, 2:15 pm, Darren Dale wrote: > > _ > > > > format1.Group # implementation of group in format1 > > > format2.Group # ... > > > Base.DerivedGro

Re: design question, metaclasses?

2009-04-12 Thread Darren Dale
On Apr 11, 2:15 pm, Darren Dale wrote: > I am working on a project that provides a high level interface to hdf5 > files by implementing a thin wrapper around h5py. I would like to > generalize the project so the same API can be used with other formats, > like netcdf or ascii files

design question, metaclasses?

2009-04-11 Thread Darren Dale
I am working on a project that provides a high level interface to hdf5 files by implementing a thin wrapper around h5py. I would like to generalize the project so the same API can be used with other formats, like netcdf or ascii files. The format specific code exists in File, Group and Dataset clas

Re: question about ctrl-d and atexit with threads

2009-03-06 Thread Darren Dale
On Mar 6, 1:32 pm, rdmur...@bitdance.com wrote: > Darren Dale wrote: > >On Mar 5, 6:27 pm, "Gabriel Genellina" wrote: > >> En Thu, 05 Mar 2009 15:26:18 -0200, Darren Dale > >> escribi : > > >> > On Mar 5, 12:02 pm, s...@pobo

Re: question about ctrl-d and atexit with threads

2009-03-06 Thread Darren Dale
On Mar 5, 6:27 pm, "Gabriel Genellina" wrote: > En Thu, 05 Mar 2009 15:26:18 -0200, Darren Dale   > escribió: > > > > > On Mar 5, 12:02 pm, s...@pobox.com wrote: > >> What happens if you simply call > > >>     my_thread.setDaemon(True) &g

Re: question about ctrl-d and atexit with threads

2009-03-06 Thread Darren Dale
On Mar 5, 6:27 pm, "Gabriel Genellina" wrote: > En Thu, 05 Mar 2009 15:26:18 -0200, Darren Dale   > escribió: > > > > > On Mar 5, 12:02 pm, s...@pobox.com wrote: > >> What happens if you simply call > > >>     my_thread.setDaemon(True) &g

Re: question about ctrl-d and atexit with threads

2009-03-05 Thread Darren Dale
On Mar 5, 12:02 pm, s...@pobox.com wrote: > What happens if you simply call > >     my_thread.setDaemon(True) > > (or in Python 2.6): > >     my_thread.daemon = True > > ?  That is the documented way to exit worker threads when you want the > application to exit.  From the threading module docs: >

Re: question about ctrl-d and atexit with threads

2009-03-05 Thread Darren Dale
Actually, this problem can also be seen by running this code as a script, it hangs up if the sys.exit lines are commented, and exits normally if uncommented. import atexit import threading import time class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(se

question about ctrl-d and atexit with threads

2009-03-05 Thread Darren Dale
I have a function that stops execution of a thread, and this function is registered with atexit.register. A simple example module is included at the end of this post, say its called test.py. If I do the following in the interactive interpreter, the thread stops executing as I hoped: >>> from test

Re: how to assert that method accepts specific types

2009-02-20 Thread Darren Dale
On Feb 20, 8:20 pm, Chris Rebert wrote: > On Fri, Feb 20, 2009 at 5:12 PM, Darren Dale wrote: > > I would like to assert that a method accepts certain types. I have a > > short example that works: > > > from functools import wraps > > > def accepts(*t

how to assert that method accepts specific types

2009-02-20 Thread Darren Dale
I would like to assert that a method accepts certain types. I have a short example that works: from functools import wraps def accepts(*types): def check_accepts(f): @wraps(f) def new_f(self, other): assert isinstance(other, types), \ "arg %r does n

Re: what gives with

2009-01-23 Thread Darren Dale
On Jan 22, 10:07 pm, Benjamin Peterson wrote: > Darren Dale gmail.com> writes: > > > Judging fromhttp://bugs.python.org/issue2400, this issue > > was fixed back in May 2008, but it is still present with python-2.5.4, > > which was released in December. Why wont py

what gives with "'import *' not allowed with 'from .'"?

2009-01-22 Thread Darren Dale
I know the use of "from foo import *" is discouraged, but I'm writing a package that I hope others may want to integrate as a subpackage of their own projects, I know what I'm doing, and I want to use the "from .bar import *" syntax internally. It works fine with python-2.6, but with python-2.5 I g

Re: is it possible to add a property to an instance?

2008-07-22 Thread Darren Dale
GHUM wrote: >> Does anyone know if it is possible to add a property to an instance at >> runtime? I didn't see anything about it in the standard library's new >> module, google hasn't turned up much either. > > yes. You need nothing special, just add it: > > class fish(object): > pass > > a

is it possible to add a property to an instance?

2008-07-22 Thread Darren Dale
Does anyone know if it is possible to add a property to an instance at runtime? I didn't see anything about it in the standard library's new module, google hasn't turned up much either. Thanks, Darren -- http://mail.python.org/mailman/listinfo/python-list

windows installers and license agreement

2008-06-29 Thread Darren Dale
Is it possible to create a windows installer using distutils that includes a prompt for the user to agree to the terms of the license? Thanks, Darren -- http://mail.python.org/mailman/listinfo/python-list

Re: python style guide inconsistencies

2007-04-23 Thread Darren Dale
Bjoern Schliessmann wrote: > Darren Dale wrote: > >> I was just searching for some guidance on how to name packages and >> modules, and discovered some inconsistencies on the >> www.python.org. http://www.python.org/doc/essays/styleguide.html >> says "Modu

python style guide inconsistencies

2007-04-22 Thread Darren Dale
I was just searching for some guidance on how to name packages and modules, and discovered some inconsistencies on the www.python.org. http://www.python.org/doc/essays/styleguide.html says "Module names can be either MixedCase or lowercase." That page also refers to PEP 8 at http://www.python.org/d

Re: string formatting: engineering notation

2007-03-14 Thread Darren Dale
[EMAIL PROTECTED] wrote: > On Mar 14, 1:14 pm, Darren Dale <[EMAIL PROTECTED]> wrote: >> Does anyone know if it is possible to represent a number as a string with >> engineering notation (like scientific notation, but with 10 raised to >> multiples of 3: 120e3, 1

Re: string formatting: engineering notation

2007-03-14 Thread Darren Dale
Steve Holden wrote: > Darren Dale wrote: >> Does anyone know if it is possible to represent a number as a string with >> engineering notation (like scientific notation, but with 10 raised to >> multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the >>

question about class methods

2007-03-14 Thread Darren Dale
I've run across some code in a class method that I don't understand: def example(self, val=0) if val and not self: if self._exp < 0 and self._exp >= -6: I am unfamiliar with some concepts here: 1) Under what circumstances would "if not self" be True? 2) If "not self" is

string formatting: engineering notation

2007-03-14 Thread Darren Dale
Does anyone know if it is possible to represent a number as a string with engineering notation (like scientific notation, but with 10 raised to multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the decimal.Decimal class, but repeatedly instantiating Decimals is inefficient for my ap

property docstrings

2006-03-24 Thread Darren Dale
I am trying to work with properties, using python 2.4.2. I can't get the docstrings to work, can someone suggest what I'm doing wrong? I think the following script should print "This is the doc string.", but instead it prints: "float(x) -> floating point number Convert a string or number to a flo

Re: How do I use the subprocess module with mswindows?

2006-03-17 Thread Darren Dale
Fredrik Lundh wrote: > Darren Dale wrote: > >> If I change my script a bit, I get a different error: >> >> import subprocess >> process = subprocess.Popen(['dir']) >> stat = process.wait() >> print process.stdout.read() > >> Wind

How do I use the subprocess module with mswindows?

2006-03-17 Thread Darren Dale
I'm a developer on the matplotlib project, and I am having trouble with the subprocess module on windows (Python 2.4.2 on winXP). No trouble to report with linux. I need to use _subprocess instead of pywin32, but my trouble exists with either option: import subprocess process = subprocess.Popen

Re: how to test for a dependency

2006-01-09 Thread Darren Dale
Sybren Stuvel wrote: > Darren Dale enlightened us with: >> I would like to test that latex is installed on a windows, mac or linux >> machine. What is the best way to do this? This should work: >> >> if os.system('latex -v'): >> print 'please

Re: how to test for a dependency

2006-01-09 Thread Darren Dale
Dennis Benzinger wrote: > Darren Dale schrieb: >> Hello, >> >> I would like to test that latex is installed on a windows, mac or linux >> machine. What is the best way to do this? This should work: >> >> if os.system('latex -v'): >>

how to test for a dependency

2006-01-09 Thread Darren Dale
Hello, I would like to test that latex is installed on a windows, mac or linux machine. What is the best way to do this? This should work: if os.system('latex -v'): print 'please install latex' but I dont actually want the latex version information to print to screen. I tried redirecting sys

Re: command line reports

2005-08-11 Thread Darren Dale
Bengt Richter wrote: > On Thu, 11 Aug 2005 15:43:23 -0400, Darren Dale <[EMAIL PROTECTED]> wrote: > >>Peter Hansen wrote: >> >>> Darren Dale wrote: >>>> Is there a module somewhere that intelligently deals with reports to >>>> the command

Re: command line reports

2005-08-11 Thread Darren Dale
Peter Hansen wrote: > Darren Dale wrote: >> Is there a module somewhere that intelligently deals with reports to the >> command line? I would like to report the progress of some pretty lengthy >> simulations, and currently I have the new reports written on a new line

command line reports

2005-08-11 Thread Darren Dale
Is there a module somewhere that intelligently deals with reports to the command line? I would like to report the progress of some pretty lengthy simulations, and currently I have the new reports written on a new line rather rather than overwriting the previous report. Thanks, Darren -- http://ma

Re: function namespaces

2005-03-08 Thread Darren Dale
> Generally, I avoid execfile within a function. What's your use case? > There may be a better way to approach this problem... I am writing a simulation that loads some predefined constants, depending on the options called by the user. I originally had it set up to parse the file, and load the c

function namespaces

2005-03-08 Thread Darren Dale
Hi, I have a variable saved in a file like this #contents of myfile.py: testvar = [1,2,3,4] and I am trying to write a function that does something like this: def myfunction(filename): execfile(filename) print testvar The problem I am running into is that the global name testva

Re: question on regular expressions

2004-12-03 Thread Darren Dale
Michael Fuhr wrote: > Darren Dale <[EMAIL PROTECTED]> writes: > >> I'm stuck. I'm trying to make this: >> >> file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C >> %5Cfolderx%5Cfoldery%5Cmydoc2.pdf >> >> (no linebreaks) look like this: &

question on regular expressions

2004-12-03 Thread Darren Dale
I'm stuck. I'm trying to make this: file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C %5Cfolderx%5Cfoldery%5Cmydoc2.pdf (no linebreaks) look like this: ./mydoc1.pdf,./mydoc2.pdf my regular expression abilities are dismal. I won't list all the unsuccessful things I've tried, in a nutshell, the