pip and different branches?

2013-05-20 Thread andrea crotti
We use github and we work on many different branches at the same time. The problem is that we have >5 repos now, and for each repo we might have the same branches on all of them. Now we use pip and install requirements such as: git+ssh://g...@github.com/repo.git@dev Now the problem is that the r

Re: Getting a callable for any value?

2013-05-29 Thread andrea crotti
On 05/29/2013 06:46 PM, Croepha wrote: Is there anything like this in the standard library? class AnyFactory(object): def __init__(self, anything): self.product = anything def __call__(self): return self.product def __repr__(self): return "%s.%s(%r)" % (self.__class__.__module__, self.__class__

decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
Using a CouchDB server we have a different database object potentially for every request. We already set that db in the request object to make it easy to pass it around form our django app, however it would be nice if I could set it once in the API and automatically fetch it from there. Basically

Re: python-django for dynamic web survey?

2013-06-18 Thread andrea crotti
Django makes your life a lot easier in many ways, but you still need some time to learn it. The task you're trying it's not trivial though, depending on your experience it might take a while with any library/framework.. -- http://mail.python.org/mailman/listinfo/python-list

Re: decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
2013/6/18 Wolfgang Maier > andrea crotti gmail.com> writes: > > > > > > > Using a CouchDB server we have a different database object potentially > for > every request. > > > > We already set that db in the request object to make it easy to pass it &

Re: decorator to fetch arguments from global objects

2013-06-18 Thread andrea crotti
2013/6/18 Terry Reedy > On 6/18/2013 5:47 AM, andrea crotti wrote: > >> Using a CouchDB server we have a different database object potentially >> for every request. >> >> We already set that db in the request object to make it easy to pass it >> around form

using SQLalchemy

2012-06-21 Thread andrea crotti
We have a very chaotic database (on MySql) at the moment, with for example table names used as keys to query other tables (but that's just an example). We are going to redesign it but first I still have to replace the perl+vbscript system with only one Python program, so I still have to deal with

retry many times decorator

2012-06-28 Thread andrea crotti
Hi everyone, I'm replacing a perl system that has to work a lot with databases and perforce (and a few other things). This script have to run completely unsupervisioned, so it's important that it doesn't just quit at the first attempt waiting for human intervent.. They say that the network someti

Re: retry many times decorator

2012-06-28 Thread andrea crotti
> Returning a boolean isn't very Pythonic. It would be better, IMHO, if > it could swallow a specified exception (or specified exceptions?) > raised when an attempt failed, up to the maximum permitted number of > attempts. If the final attempt fails, propagate the exception. > -- > http://mail.pyth

Re: retry many times decorator

2012-06-28 Thread Andrea Crotti
On 06/28/2012 06:43 PM, Steven D'Aprano wrote: On Thu, 28 Jun 2012 17:26:36 +0100, andrea crotti wrote: I disagree. If you make a coding error in your function, why do you think it is useful to retry that buggy code over and over again? It's never going to get less buggy unless y

Re: retry many times decorator

2012-06-29 Thread andrea crotti
On the other hand now that I think again even supposing there is a permanent error like MySql completely down, retrying continuosly won't do any harm anyway because the machine will not be able to do anything else anyway, when someone will fix MySql it would restart again without human intervention

adding a simulation mode

2012-07-04 Thread andrea crotti
I'm writing a program which has to interact with many external resources, at least: - mysql database - perforce - shared mounts - files on disk And the logic is quite complex, because there are many possible paths to follow depending on some other parameters. This program even needs to run on many

Re: adding a simulation mode

2012-07-04 Thread andrea crotti
2012/7/4 Steven D'Aprano : > > Then, have your code accept the thing as an argument. > > E.g. instead of having a hard-coded database connection, allow the > database connection to be set (perhaps as an argument, perhaps as a > config option, etc.). > > There are libraries to help with mocks, e.g.:

Re: adding a simulation mode

2012-07-04 Thread andrea crotti
> Yes there is no easy solution apparently.. But I'm also playing > around with vagrant and virtual machine generations, suppose I'm able > to really control what will be on the machine at time X, creating it > on demand with what I need, it might be a good way to solve my > problems (a bit overki

Re: adding a simulation mode

2012-07-05 Thread andrea crotti
2012/7/5 Dieter Maurer : > > There is a paradigm called "inversion of control" which can be used > to handle those requirements. > > With "inversion of control", the components interact on the bases > of interfaces. The components themselves do not know each other, they > know only the interfaces t

Re: stuck in files!!

2012-07-06 Thread andrea crotti
2012/7/6 Chirag B : > i want to kno how to link two applications using python for eg:notepad > txt file and some docx file. like i wat to kno how to take path of > those to files and run them simultaneously.like if i type something in > notepad it has to come in wordpad whenever i run that code. >

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
One thing that I don't quite understand is why some calls even if I catch the exception still makes the whole program quit. For example this try: copytree('sjkdf', 'dsflkj') Popen(['notfouhd'], shell=True) except Exception as e: print("here") behaves differently f

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
One way instead that might actually work is this def default_mock_action(func_name): def _default_mock_action(*args, **kwargs): print("running {} with args {} and {}".format(func_name, args, kwargs)) return _default_mock_action def mock_fs_actions(to_run): """Take a function

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
Well that's what I thought, but I can't find any explicit exit anywhere in shutil, so what's going on there? -- http://mail.python.org/mailman/listinfo/python-list

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
2012/7/12 John Gordon : > In andrea crotti > writes: > >> Well that's what I thought, but I can't find any explicit exit >> anywhere in shutil, so what's going on there? > > Try catching SystemExit specifically (it doesn't inherit from Ex

Re: adding a simulation mode

2012-07-13 Thread andrea crotti
2012/7/13 Steven D'Aprano : > Well of course it does. If copytree fails, the try block ends and > execution skips straight to the except block, which runs, and then the > program halts because there's nothing else to be done. > > That at least is my guess, based on the described symptoms. > Well

assertraises behaviour

2012-07-16 Thread andrea crotti
I found that the behaviour of assertRaises used as a context manager a bit surprising. This small example doesn't fail, but the OSError exception is cathed even if not declared.. Is this the expected behaviour (from the doc I would say it's not). (Running on arch-linux 64 bits and Python 2.7.3, bu

Re: assertraises behaviour

2012-07-16 Thread andrea crotti
2012/7/16 Christian Heimes : > > The OSError isn't catched as the code never reaches the line with "raise > OSError". In other words "raise OSError" is never executed as the > exception raised by "assert False" stops the context manager. > > You should avoid testing more than one line of code in a

Re: assertraises behaviour

2012-07-16 Thread andrea crotti
Good thanks, but there is something that implements this behaviour.. For example nose runs all the tests, and if there are failures it goes on and shows the failed tests only in the end, so I think it is possible to achieve somehow, is that correct? -- http://mail.python.org/mailman/listinfo/pytho

Re: Diagramming code

2012-07-16 Thread Andrea Crotti
On 07/16/2012 02:26 AM, hamilton wrote: Is there any software to help understand python code ? Thanks hamilton Sometimes to get some nice graphs I use gprof2dot (http://code.google.com/p/jrfonseca/wiki/Gprof2Dot) or doxygen (http://www.stack.nl/~dimitri/doxygen/) gprof2dot analyses the out

Re: assertraises behaviour

2012-07-17 Thread andrea crotti
2012/7/16 Peter Otten <__pete...@web.de>: > No, I don't see how the code you gave above can fail with an OSError. > > Can you give an example that produces the desired behaviour with nose? Maybe > we can help you translate it to basic unittest. > > -- > http://mail.python.org/mailman/listinfo/pytho

Re: assertraises behaviour

2012-07-17 Thread Andrea Crotti
To clarify my "problem", I just thought that assertRaises if used as context manager should behave as following: - keep going if the exception declared is raised - re-raise an error even if catched after the declared exception was catched I was also confused by the doc a bit: "Test that an excep

reloading code and multiprocessing

2012-07-19 Thread andrea crotti
We need to be able to reload code on a live system. This live system has a daemon process always running but it runs many subprocesses with multiprocessing, and the subprocesses might have a short life... Now I found a way to reload the code successfully, as you can see from this testcase: def

Re: reloading code and multiprocessing

2012-07-23 Thread andrea crotti
2012/7/20 Chris Angelico : > On Thu, Jul 19, 2012 at 8:15 PM, andrea crotti > wrote: >> We need to be able to reload code on a live system. This live system >> has a daemon process always running but it runs many subprocesses with >> multiprocessing, and the subprocesses

Re: reloading code and multiprocessing

2012-07-25 Thread andrea crotti
2012/7/23 Chris Angelico : > > That would probably be correct. However, I still think you may be > fighting against the language instead of playing to its strengths. > > I've never fiddled with sys.modules like that, but I know some have, > without problem. > > ChrisA > -- > http://mail.python.org/

Dumping all the sql statements as backup

2012-07-25 Thread andrea crotti
I have some long running processes that do very long simulations which at the end need to write things on a database. At the moment sometimes there are network problems and we end up with half the data on the database. The half-data problem is probably solved easily with sessions and sqlalchemy (

Re: Dumping all the sql statements as backup

2012-07-25 Thread andrea crotti
2012/7/25 Jack Since you know the content of what the sql code is, why not just build > the sql file(s) needed and store them so that in case of a burp you can > just execute the code file. If you don't know the exact sql code, dump > it to a file as the statements are constructed... The only prob

regexps to objects

2012-07-27 Thread andrea crotti
I have some complex input to parse (with regexps), and I would like to create nice objects directy from them. The re module doesn't of course try to conver to any type, so I was playing around to see if it's worth do something as below, where I assign a constructor to every regexp and build an obje

Re: reloading code and multiprocessing

2012-07-27 Thread andrea crotti
2012/7/25 andrea crotti : > > I would also like to avoid this in general, but we have many > subprocesses to launch and some of them might take weeks, so we need > to have a process which is always running, because there is never a > point in time where we can just say let's

Re: py2c - an open source Python to C/C++ is looking for developers

2012-07-30 Thread andrea crotti
2012/7/30 : > I created py2c ( http://code.google.com/p/py2c )- an open source Python to > C/C++ translator! > py2c is looking for developers! > To join create a posting in the py2c-discuss Google Group or email me! > Thanks > PS:I hope this is the appropiate group for this message. > -- > http:/

Re: Pass data to a subprocess

2012-07-31 Thread andrea crotti
> > > def procs(): > mp = MyProcess() > # with the join we are actually waiting for the end of the running time > mp.add([1,2,3]) > mp.start() > mp.add([2,3,4]) > mp.join() > print(mp) > I think I got it now, if I already just mix the start before another add, inside th

Re: Pass data to a subprocess

2012-07-31 Thread andrea crotti
2012/7/31 Laszlo Nagy : >> I think I got it now, if I already just mix the start before another add, >> inside the Process.run it won't see the new data that has been added after >> the start. So this way is perfectly safe only until the process is launched, >> if it's running I need to use some mu

Re: Pass data to a subprocess

2012-08-01 Thread andrea crotti
2012/8/1 Laszlo Nagy : >> I was just surprised that it worked better than I expected even >> without Pipes and Queues, but now I understand why.. >> >> Anyway now I would like to be able to detach subprocesses to avoid the >> nasty code reloading that I was talking about in another thread, but >> t

Re: Pass data to a subprocess

2012-08-01 Thread andrea crotti
2012/8/1 Laszlo Nagy : > On thing is sure: os.fork() doesn't work under Microsoft Windows. Under > Unix, I'm not sure if os.fork() can be mixed with > multiprocessing.Process.start(). I could not find official documentation on > that. This must be tested on your actual platform. And don't forget t

CRC-checksum failed in gzip

2012-08-01 Thread andrea crotti
We're having some really obscure problems with gzip. There is a program running with python2.7 on a 2.6.18-128.el5xen (red hat I think) kernel. Now this program does the following: if filename == 'out2.txt': out2 = open('out2.txt') elif filename == 'out2.txt.gz' out2 = open('out2.txt.gz'

Re: CRC-checksum failed in gzip

2012-08-01 Thread andrea crotti
2012/8/1 Laszlo Nagy : > On 2012-08-01 12:39, andrea crotti wrote: >> >> We're having some really obscure problems with gzip. >> There is a program running with python2.7 on a 2.6.18-128.el5xen (red >> hat I think) kernel. >> >> Now this program doe

Re: CRC-checksum failed in gzip

2012-08-01 Thread andrea crotti
Full traceback: Exception in thread Thread-8: Traceback (most recent call last): File "/user/sim/python/lib/python2.7/threading.py", line 530, in __bootstrap_inner self.run() File "/user/sim/tests/llif/AutoTester/src/AutoTester2.py", line 67, in run self.processJobData(jobData, logger)

Re: Pass data to a subprocess

2012-08-01 Thread andrea crotti
2012/8/1 Roy Smith : > In article , > Laszlo Nagy wrote: > >> Yes, I think that is correct. Instead of detaching a child process, you >> can create independent processes and use other frameworks for IPC. For >> example, Pyro. It is not as effective as multiprocessing.Queue, but in >> return, you

Re: CRC-checksum failed in gzip

2012-08-01 Thread andrea crotti
2012/8/1 Laszlo Nagy : >>there seems to be no clear pattern and just randmoly fails. The file >> is also just open for read from this program, >>so in theory no way that it can be corrupted. > > Yes, there is. Gzip stores CRC for compressed *blocks*. So if the file is > not flushed to the d

Re: Pass data to a subprocess

2012-08-01 Thread andrea crotti
2012/8/1 Laszlo Nagy : > > So detaching the child process will not make IPC stop working. But exiting > from the original parent process will. (And why else would you detach the > child?) > > -- > http://mail.python.org/mailman/listinfo/python-list Well it makes perfect sense if it stops working

Re: CRC-checksum failed in gzip

2012-08-01 Thread andrea crotti
2012/8/1 Steven D'Aprano : > On Wed, 01 Aug 2012 14:01:45 +0100, andrea crotti wrote: > >> Full traceback: >> >> Exception in thread Thread-8: > > "DANGER DANGER DANGER WILL ROBINSON!!!" > > Why didn't you say that there were threads involve

Re: CRC-checksum failed in gzip

2012-08-01 Thread andrea crotti
2012/8/1 Laszlo Nagy : > >> Thanks a lot, that makes a lot of sense.. I haven't given this detail >> before because I didn't write this code, and I forgot that there were >> threads involved completely, I'm just trying to help to fix this bug. >> >> Your explanation makes a lot of sense, but it's

Re: CRC-checksum failed in gzip

2012-08-02 Thread andrea crotti
2012/8/1 Steven D'Aprano : > > When you start using threads, you have to expect these sorts of > intermittent bugs unless you are very careful. > > My guess is that you have a bug where two threads read from the same file > at the same time. Since each read shares state (the position of the file >

Re: CRC-checksum failed in gzip

2012-08-02 Thread andrea crotti
2012/8/2 Laszlo Nagy : > > Your example did not share the file object between threads. Here an example > that does that: > > class OpenAndRead(threading.Thread): > def run(self): > global fz > fz.read(100) > > if __name__ == '__main__': > >fz = gzip.open('out2.txt.gz') >

Re: CRC-checksum failed in gzip

2012-08-02 Thread andrea crotti
2012/8/2 andrea crotti : > > Ok sure that makes sense, but then this explanation is maybe not right > anymore, because I'm quite sure that the file object is *not* shared > between threads, everything happens inside a thread.. > > I managed to get some errors doing this

Sharing code between different projects?

2012-08-13 Thread andrea crotti
I am in the situation where I am working on different projects that might potentially share a lot of code. I started to work on project A, then switched completely to project B and in the transiction I copied over a lot of code with the corresponding tests, and I started to modify it. Now it's ti

Re: Sharing code between different projects?

2012-08-14 Thread andrea crotti
2012/8/13 Rob Day : > I'd just create a module - called shared_utils.py or similar - and import > that in both projects. It might be a bit messy if there's no 'unifying > theme' to the module - but surely it'd be a lot less messy than your > TempDirectory class, and anyone else who knows Python wil

Re: Sharing code between different projects?

2012-08-14 Thread andrea crotti
2012/8/14 Jean-Michel Pichavant : > > I can think of logilab-common (http://www.logilab.org/848/) > > Having a company-wide python module properly distributed is one to achieve > your goal. Without distributing your module to the public, there's a way to > have a pypi-like server runnning on your p

Re: Sharing code between different projects?

2012-08-15 Thread andrea crotti
2012/8/14 Cameron Simpson : > > Having just skimmed this thread, one thing I haven't quite seen suggested is > this: > > Really do make a third "utilities" project, and treat "the project" and > "deploy" as separate notions. So to actually run/deploy project A's code > you'd have a short script tha

Re: Sharing code between different projects?

2012-08-15 Thread andrea crotti
Also looking at logilab-common I thought that it would be great if we could actually make this "common" library even open source, and use it as one of the other many external libraries. Since Python code is definitively not the the core business of this company I might even convince them, but the

Re: Sharing code between different projects?

2012-08-16 Thread andrea crotti
2012/8/16 Jean-Michel Pichavant : > > SVN allows to define external dependencies, where one repository will > actually checkout another one at a specific version. If SVN does it, I guess > any decent SCM also provide such feature. > > Assuming our project is named 'common', and you have 2 projects

Re: how to call perl script from html using python

2012-08-16 Thread andrea crotti
2012/8/16 Pervez Mulla : > > Hey Steven , > > Thank you for your response, > > I will in detail now about my project, > > Actually the project entire backend in PERL language , Am using Django > framework for my front end . > I have written code for signup page in python , which is working perfec

Re: Sharing code between different projects?

2012-08-16 Thread andrea crotti
2012/8/16 andrea crotti : > > > Unfortunately I think you guess wrong > http://forums.perforce.com/index.php?/topic/553-perforce-svnexternals-equivalent/ > Anyway with views and similar things is not that hard to implement the > same thing.. I'm very happy to say that I fi

Re: Why doesn't Python remember the initial directory?

2012-08-20 Thread andrea crotti
2012/8/20 kj : > In Roy Smith > writes> This means that no library code can ever count on, for example, > being able to reliably find the path to the file that contains the > definition of __main__. That's a weakness, IMO. One manifestation > of this weakness is that os.chdir breaks inspect.ge

Re: Why doesn't Python remember the initial directory?

2012-08-20 Thread andrea crotti
2012/8/20 Roy Smith : > In article , > Walter Hurry wrote: > >> It is difficult to think of a sensible use for os.chdir, IMHO. > > It is true that you can mostly avoid chdir() by building absolute > pathnames, but it's often more convenient to just cd somewhere and use > names relative to that.

Re: pyQT performance?

2012-09-10 Thread Andrea Crotti
On 09/10/2012 07:29 PM, jayden.s...@gmail.com wrote Have you ever used py2exe? After converting the python codes to executable, does it save the time of interpreting the script language? Thank a lot! Py2exe normally never speeds up anything, simply because it doesn't convert to executable, bu

main and dependent objects

2012-09-13 Thread andrea crotti
I am in a situation where I have a class Obj which contains many attributes, and also contains logically another object of class Dependent. This dependent_object, however, also needs to access many fields of the original class, so at the moment we did something like this: class Dependent: de

Re: main and dependent objects

2012-09-13 Thread andrea crotti
2012/9/13 Jean-Michel Pichavant : > > Nothing shocking right here imo. It looks like a classic parent-child > implementation. > However it seems the relation between Obj and Dependent are 1-to-1. Since > Dependent need to access all Obj attributes, are you sure that Dependent and > Obj are not a

Re: Python presentations

2012-09-13 Thread andrea crotti
2012/9/13 William R. Wing (Bill Wing) : > > [byte] > > Speaking from experience as both a presenter and an audience member, please > be sure that anything you demo interactively you include in your slide deck > (even if only as an addendum). I assume your audience will have access to > the deck

Re: Python presentations

2012-09-13 Thread Andrea Crotti
On 09/13/2012 11:58 PM, Miki Tebeka wrote: What do you think work best in general? I find typing during class (other than small REPL examples) time consuming and error prone. What works well for me is to create a slidy HTML presentation with asciidoc, then I can include code snippets that can

Re: Decorators not worth the effort

2012-09-14 Thread andrea crotti
I think one very nice and simple example of how decorators can be used is this: def memoize(f, cache={}, *args, **kwargs): def _memoize(*args, **kwargs): key = (args, str(kwargs)) if not key in cache: cache[key] = f(*args, **kwargs) return cache[key] r

Re: Decorators not worth the effort

2012-09-14 Thread andrea crotti
2012/9/14 Chris Angelico : > > Trouble is, you're starting with a pretty poor algorithm. It's easy to > improve on what's poor. Memoization can still help, but I would start > with a better algorithm, such as: > > def fib(n): > if n<=1: return 1 > a,b=1,1 > for i in range(1,

Re: subprocess call is not waiting.

2012-09-18 Thread andrea crotti
I have a similar problem, something which I've never quite understood about subprocess... Suppose I do this: proc = subprocess.Popen(['ls', '-lR'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) now I created a process, which has a PID, but it's not running apparently... It only seems to run whe

Re: subprocess call is not waiting.

2012-09-19 Thread andrea crotti
2012/9/18 Dennis Lee Bieber : > > Unless you have a really massive result set from that "ls", that > command probably ran so fast that it is blocked waiting for someone to > read the PIPE. I tried also with "ls -lR /" and that definitively takes a while to run, when I do this: proc = subp

Re: subprocess call is not waiting.

2012-09-19 Thread andrea crotti
2012/9/19 Hans Mulder : > Yes: using "top" is an observation problem. > > "Top", as the name suggests, shows only the most active processes. Sure but "ls -lR /" is a very active process if you try to run it.. Anyway as written below I don't need this anymore. > > It's quite possible that your 'ls

Re: Python presentations

2012-09-19 Thread andrea crotti
2012/9/19 Trent Nelson : > > FWIW, I gave a presentation on decorators to the New York Python > User Group back in 2008. Relevant blog post: > > http://blogs.onresolve.com/?p=48 > > There's a link to the PowerPoint presentation I used in the first > paragraph. It's in .ppt

Re: 'str' object does not support item assignment

2012-09-23 Thread Andrea Crotti
On 09/23/2012 07:31 PM, jimbo1qaz wrote: spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though: a=[["a"]] a[0][0]="b" and: a=[["a"]] a[0][0]=100 both work. Spots is a nested list created as a copy of another list. But a = "a" a[0] = 'c' fails f

Re: Python presentations

2012-09-24 Thread andrea crotti
For anyone interested, I already moved the slides on github (https://github.com/AndreaCrotti/pyconuk2012_slides) and for example the decorator slides will be generated from this: https://raw.github.com/AndreaCrotti/pyconuk2012_slides/master/deco_context/deco.rst Notice the literalinclude with :py

Re: PHP vs. Python

2012-09-25 Thread andrea crotti
2012/9/25 : > On Thursday, 23 December 2004 03:33:36 UTC+5:30, (unknown) wrote: >> Anyone know which is faster? I'm a PHP programmer but considering >> getting into Python ... did searches on Google but didn't turn much up >> on this. >> >> Thanks! >> Stephen > > > Here some helpful gudance. > >

Re: Generating C++ code

2012-10-09 Thread Andrea Crotti
On 10/09/2012 05:00 PM, Jean-Michel Pichavant wrote: Greetings, I'm trying to generate C++ code from an XML file. I'd like to use a template engine, which imo produce something readable and maintainable. My google search about this subject has been quite unsuccessful, I've been redirected to t

Re: Generating C++ code

2012-10-10 Thread andrea crotti
2012/10/10 Jean-Michel Pichavant : > Well, the C++ code will end up running on a MIPS on a SOC, unfortunately, > python is not an option here. > The xml to C++ makes a lot of sense, because only a small part of the code is > generated that way (everything related to log & fatal events). Everythin

Re: locking files on Linux

2012-10-18 Thread andrea crotti
2012/10/18 Grant Edwards : > On 2012-10-18, andrea crotti wrote: > > > File locks under Unix have historically been "advisory". That means > that programs have to _choose_ to pay attention to them. Most > programs do not. > > Linux does support mandatory lock

Re: locking files on Linux

2012-10-18 Thread andrea crotti
2012/10/18 Oscar Benjamin : > > Why not come up with a test that actually shows you if it works? Here > are two suggestions: > > 1) Use time.sleep() so that you know how long the lock is held for. > 2) Write different data into the file from each process and see what > you end up with. > Ok thank

Re: Testing against multiple versions of Python

2012-10-19 Thread andrea crotti
2012/10/19 Michele Simionato : > Yesterday I released a new version of the decorator module. It should run > under Python 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3. I did not have the will > to install on my machine 8 different versions of Python, so I just tested it > with Python 2.7 and 3.3. But

Re: locking files on Linux

2012-10-19 Thread andrea crotti
2012/10/18 Oscar Benjamin : > > The lock is cooperative. It does not prevent the file from being > opened or overwritten. It only prevents any other process from > obtaining the lock. Here you open the file with mode 'w' which > truncates the file instantly (without checking for the lock). > > > Os

resume execution after catching with an excepthook?

2012-10-24 Thread andrea crotti
So I would like to be able to ask for confirmation when I receive a C-c, and continue if the answer is "N/n". I'm already using an exception handler set with sys.excepthook, but I can't make it work with the confirm_exit, because it's going to quit in any case.. A possible solution would be to do

Re: resume execution after catching with an excepthook?

2012-10-25 Thread andrea crotti
2012/10/25 Steven D'Aprano : > On Wed, 24 Oct 2012 13:51:30 +0100, andrea crotti wrote: > >> So I would like to be able to ask for confirmation when I receive a C-c, >> and continue if the answer is "N/n". > > I don't think there is any way to do thi

Re: Immutability and Python

2012-10-29 Thread andrea crotti
2012/10/29 Jean-Michel Pichavant : > > "return NumWrapper(self.number + 1) " > > still returns a(nother) mutable object. > > So what's the point of all this ? > > JM > Well sure but it doesn't modify the first object, just creates a new one. There are in general good reasons to do that, for examp

Re: Immutability and Python

2012-10-29 Thread andrea crotti
2012/10/29 andrea crotti : >> > > Well sure but it doesn't modify the first object, just creates a new > one. There are in general good reasons to do that, for example I can > then compose things nicely: > > num.increment().increment() > > or I can parallelize

Re: Immutability and Python

2012-10-29 Thread andrea crotti
2012/10/29 Jean-Michel Pichavant : > > > In an OOP language num.increment() is expected to modify the object in place. > So I think you're right when you say that functional languages technics do > not necessarily apply to Python, because they don't. > > I would add that what you're trying to sugg

Re: Immutability and Python

2012-10-29 Thread andrea crotti
2012/10/29 Chris Angelico : > On Tue, Oct 30, 2012 at 2:55 AM, Paul Rubin wrote: >> andrea crotti writes: >>> and we want to change its state incrementing the number ... >>> the immutability purists would instead suggest to do this: >>> def increment(

Re: Nice solution wanted: Hide internal interfaces

2012-10-29 Thread andrea crotti
2012/10/29 Johannes Bauer : > Hi there, > > I'm currently looking for a good solution to the following problem: I > have two classes A and B, which interact with each other and which > interact with the user. Instances of B are always created by A. > > Now I want A to call some private methods of B

Re: Nice solution wanted: Hide internal interfaces

2012-10-30 Thread andrea crotti
2012/10/30 alex23 : > On Oct 30, 2:33 am, Johannes Bauer wrote: >> I'm currently looking for a good solution to the following problem: I >> have two classes A and B, which interact with each other and which >> interact with the user. Instances of B are always created by A. >> >> Now I want A to ca

lazy properties?

2012-11-01 Thread Andrea Crotti
Seeing the wonderful "lazy val" in Scala I thought that I should try to get the following also in Python. The problem is that I often have this pattern in my code: class Sample: def __init__(self): self._var = None @property def var(self): if self._var is None:

Re: accepting file path or file object?

2012-11-05 Thread andrea crotti
2012/11/5 Peter Otten <__pete...@web.de>: > I sometimes do something like this: > > $ cat xopen.py > import re > import sys > from contextlib import contextmanager > > @contextmanager > def xopen(file=None, mode="r"): > if hasattr(file, "read"): > yield file > elif file == "-": >

Re: creating size-limited tar files

2012-11-07 Thread Andrea Crotti
On 11/07/2012 08:32 PM, Roy Smith wrote: In article <509ab0fa$0$6636$9b4e6...@newsspool2.arcor-online.net>, Alexander Blinne wrote: I don't know the best way to find the current size, I only have a general remark. This solution is not so good if you have to impose a hard limit on the resulti

Re: creating size-limited tar files

2012-11-08 Thread andrea crotti
2012/11/7 Oscar Benjamin : > > Correct. But if you read the rest of Alexander's post you'll find a > suggestion that would work in this case and that can guarantee to give > files of the desired size. > > You just need to define your own class that implements a write() > method and then distributes

Re: creating size-limited tar files

2012-11-08 Thread andrea crotti
2012/11/8 andrea crotti : > > > > Yes yes I saw the answer, but now I was thinking that what I need is > simply this: > tar czpvf - /path/to/archive | split -d -b 100M - tardisk > > since it should run only on Linux it's probably way easier, my script > will then

Re: creating size-limited tar files

2012-11-14 Thread andrea crotti
2012/11/14 Kushal Kumaran : > > Well, well, I was wrong, clearly. I wonder if this is fixable. > > -- > regards, > kushal > -- > http://mail.python.org/mailman/listinfo/python-list But would it not be possible to use the pipe in memory in theory? That would be way faster and since I have in theor

Re: creating size-limited tar files

2012-11-14 Thread andrea crotti
2012/11/14 Dave Angel : > On 11/14/2012 10:56 AM, andrea crotti wrote: >> Ok this is all very nice, but: >> >> [andrea@andreacrotti tar_baller]$ time python2 test_pipe.py > /dev/null >> >> real 0m21.215s >> user 0m0.750s >> sys 0m1.703s >>

Re: creating size-limited tar files

2012-11-14 Thread Andrea Crotti
On 11/14/2012 04:33 PM, Dave Angel wrote: Well, as I said, I don't see how the particular timing has anything to do with the rest of the thread. If you want to do an ls within a Python program, go ahead. But if all you need can be done with ls itself, then it'll be slower to launch python just

Re: forking and avoiding zombies!

2012-12-11 Thread andrea crotti
Yes I wanted to avoid to do something too complex, anyway I'll just comment it well and add a link to the original code.. But this is now failing to me: def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # Perform first fork. try: pid = os.fork() if

Re: forking and avoiding zombies!

2012-12-11 Thread andrea crotti
Ah sure that makes sense! But actually why do I need to move away from the current directory of the parent process? In my case it's actually useful to be in the same directory, so maybe I can skip that part, or otherwise I need another chdir after.. -- http://mail.python.org/mailman/listinfo/pyth

Re: forking and avoiding zombies!

2012-12-11 Thread andrea crotti
2012/12/11 peter : > On 12/11/2012 10:25 AM, andrea crotti wrote: >> >> Ah sure that makes sense! >> >> But actually why do I need to move away from the current directory of >> the parent process? >> In my case it's actually useful to be in the same

Re: forking and avoiding zombies!

2012-12-11 Thread andrea crotti
2012/12/11 Jean-Michel Pichavant : > - Original Message - >> So I implemented a simple decorator to run a function in a forked >> process, as below. >> >> It works well but the problem is that the childs end up as zombies on >> one machine, while strangely >> I can't reproduce the same on m

  1   2   3   4   >