select(sock) indicates not-ready, but sock.recv does not block

2014-02-16 Thread Nikolaus Rath
Hello, I have a problem with using select. I can reliably reproduce a situation where select.select((sock.fileno(),), (), (), 0) returns ((),(),()) (i.e., no data ready for reading), but an immediately following sock.recv() returns data without blocking. I am pretty sure that this is not a race c

Re: select(sock) indicates not-ready, but sock.recv does not block

2014-02-17 Thread Nikolaus Rath
Nikolaus Rath writes: > Hello, > > I have a problem with using select. I can reliably reproduce a situation > where select.select((sock.fileno(),), (), (), 0) returns ((),(),()) > (i.e., no data ready for reading), but an immediately following > sock.recv() returns dat

Corrputed stacktrace?

2014-06-03 Thread Nikolaus Rath
Hello, I'm trying to debug a problem. As far as I can tell, one of my methods is called at a point where it really should not be called. When setting a breakpoint in the function, I'm getting this: > /home/nikratio/in-progress/s3ql/src/s3ql/backends/s3c.py(693)close() -> if not self.md5_checked:

Missing stack frames?

2014-06-03 Thread Nikolaus Rath
Hello, (This may or may not be related to my mail about a "corrupted stack trace"). I've instrumented one of my unit tests with a conditional 'pdb.set_trace' in some circumstances (specifically, when a function is called by a thread other than MainThread). However, when trying to print a back tra

Re: Missing stack frames?

2014-06-04 Thread Nikolaus Rath
Chris Angelico writes: > On Wed, Jun 4, 2014 at 12:30 PM, Nikolaus Rath wrote: >> I've instrumented one of my unit tests with a conditional >> 'pdb.set_trace' in some circumstances (specifically, when a function is >> called by a thread other than MainThread)

Re: Corrputed stacktrace?

2014-06-04 Thread Nikolaus Rath
Chris Angelico writes: > On Wed, Jun 4, 2014 at 12:20 PM, Nikolaus Rath wrote: >> File "/usr/lib/python3.3/threading.py", line 878 in _bootstrap > > Can you replicate the problem in a non-threaded environment? Threads > make interactive debugging very hairy. Hmm. I

Re: Missing stack frames?

2014-06-04 Thread Nikolaus Rath
Chris Angelico writes: > On Wed, Jun 4, 2014 at 12:30 PM, Nikolaus Rath wrote: >> I've instrumented one of my unit tests with a conditional >> 'pdb.set_trace' in some circumstances (specifically, when a function is >> called by a thread other than MainThread)

Re: Missing stack frames?

2014-06-05 Thread Nikolaus Rath
Paul Rubin writes: > Nikolaus Rath writes: >> Still no context before the ominous close() call. I'm very confused. > > close() could be getting called from a destructor as the top level > function of a thread exits, or something like that. Shouldn't the destructor h

Re: Missing stack frames?

2014-06-05 Thread Nikolaus Rath
Nikolaus Rath writes: > Chris Angelico writes: >> On Wed, Jun 4, 2014 at 12:30 PM, Nikolaus Rath wrote: >>> I've instrumented one of my unit tests with a conditional >>> 'pdb.set_trace' in some circumstances (specifically, when a function is &g

Re: Missing stack frames?

2014-06-05 Thread Nikolaus Rath
dieter writes: [...] > Someone else already mentioned that the "close" call > can come from a destructor. Destructors can easily be called > at not obvious places (e.g. "s = C(); ... x = [s for s in ...]"; > in this example the list comprehension calls the "C" destructor > which is not obvious whe

Re: Missing stack frames?

2014-06-06 Thread Nikolaus Rath
Chris Angelico writes: > On Fri, Jun 6, 2014 at 12:16 PM, Nikolaus Rath wrote: >> - Is there some way to make the call stack for destructors less confusing? > > First off, either don't have refloops, or explicitly break them. The actual code isn't as simple as the exa

ssl.SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1636)

2014-09-21 Thread Nikolaus Rath
Hello, Can someone explain help me understand what this exception means? [...] File "/usr/local/lib/python3.4/dist-packages/dugong-3.2-py3.4.egg/dugong/__init__.py", line 584, in _co_send len_ = self._sock.send(buf) File "/usr/lib/python3.4/ssl.py", line 679, in send v = self._sslob

Strange pexpect behaviour: just duplicates stdin

2009-03-30 Thread Nikolaus Rath
Hello, I have a strange problem with pexpect: $ cat test.py #!/usr/bin/python import pexpect child = pexpect.spawn("./test.pl") while True: try: line = raw_input() except EOFError: break child.sendline(line) print child.readline().rstrip("\r\n") child.close()

[pyunit] Only run one specific test

2009-05-28 Thread Nikolaus Rath
Hi, Consider these two files: , mytest.py - | #!/usr/bin/env python | import unittest | | class myTestCase(unittest.TestCase): | def test_foo(self): | pass | | # Somehow important according to pyunit documentation | def suite(): | return unittest.makeSuite(myTestCase) `---

Re: [pyunit] Only run one specific test

2009-05-28 Thread Nikolaus Rath
Dave Angel writes: > Nikolaus Rath wrote: >> Hi, >> >> Consider these two files: >> >> , mytest.py - >> | #!/usr/bin/env python >> | import unittest >> | | class myTestCase(unittest.TestCase): >> | def test_foo(self): &g

Protecting instance variables

2008-07-18 Thread Nikolaus Rath
Hello, I am really surprised that I am asking this question on the mailing list, but I really couldn't find it on python.org/doc. Why is there no proper way to protect an instance variable from access in derived classes? I can perfectly understand the philosophy behind not protecting them from a

Re: Attack a sacred Python Cow

2008-07-25 Thread Nikolaus Rath
Terry Reedy <[EMAIL PROTECTED]> writes: > Torsten Bronger wrote: >> Hallöchen! > > And why does this make the implicit insertion of "self" difficult? >> I could easily write a preprocessor which does it after all. > > class C(): > def f(): > a = 3 > > Inserting self into the arg list is triv

Re: Attack a sacred Python Cow

2008-07-26 Thread Nikolaus Rath
Terry Reedy <[EMAIL PROTECTED]> writes: > Nikolaus Rath wrote: >> Terry Reedy <[EMAIL PROTECTED]> writes: >>> Torsten Bronger wrote: >>>> Hallöchen! >>> > And why does this make the implicit insertion of "self" difficult? >>>

Re: Attack a sacred Python Cow

2008-07-27 Thread Nikolaus Rath
Terry Reedy <[EMAIL PROTECTED]> writes: >> What he wants is to write >> > > > class foo: >>def bar(arg): >>self.whatever = arg + 1 >> >> instead of >> >> class foo: >>def bar(self, arg) >>self.whatever = arg + 1 >> >> so 'self' should *automatically* only be inserted in the

Re: Attack a sacred Python Cow

2008-07-28 Thread Nikolaus Rath
castironpi <[EMAIL PROTECTED]> writes: >> I think you misunderstood him. What he wants is to write >> >> class foo: >>    def bar(arg): >>        self.whatever = arg + 1 >> >> instead of >> >> class foo: >>    def bar(self, arg) >>        self.whatever = arg + 1 >> >> so 'self' should *automaticall

Re: Attack a sacred Python Cow

2008-07-28 Thread Nikolaus Rath
Michael Torrie <[EMAIL PROTECTED]> writes: > Colin J. Williams wrote: >>> >>> def fun( ., cat): >>> >> I don't see the need for the comma in fun. > > It (the entire first variable!) is needed because a method object is > constructed from a normal function object: > > def method(self,a,b): >

Re: Attack a sacred Python Cow

2008-07-28 Thread Nikolaus Rath
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > The fact that a function is defined within a class statement doesn't > imply any "magic", it just creates a function object, bind it to a > name, and make that object an attribute of the class. You have the > very same result by defining the functio

Re: Attack a sacred Python Cow

2008-07-28 Thread Nikolaus Rath
"Russ P." <[EMAIL PROTECTED]> writes: > The issue here has nothing to do with the inner workings of the Python > interpreter. The issue is whether an arbitrary name such as "self" > needs to be supplied by the programmer. > > All I am suggesting is that the programmer have the option of > replacing

Re: Attack a sacred Python Cow

2008-07-28 Thread Nikolaus Rath
Michael Torrie <[EMAIL PROTECTED]> writes: > I think the biggest reason why an implicit self is bad is because it > prevents monkey-patching of existing class objects. Right now I can add > a new method to any existing class just with a simple attribute like so > (adding a new function to an exist

os.symlink()

2008-07-28 Thread Nikolaus Rath
Hello, From `pydoc os`: symlink(...) symlink(src, dst) Create a symbolic link pointing to src named dst. Is there any reason why this is so deliberately confusing? Why is the target of the symlink, the think where it points *to*, called the `src`? It seems to me tha

Re: os.symlink()

2008-07-28 Thread Nikolaus Rath
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > Nikolaus Rath wrote: > >> Hello, >> >>>From `pydoc os`: >> >> symlink(...) >> symlink(src, dst) >> >> Create a symbolic link pointing to

Re: Protecting instance variables

2008-07-28 Thread Nikolaus Rath
Hi, Sorry for replying so late. Your MUA apparently messes up the References:, so I saw you reply only now and by coincidence. "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > Nikolaus Rath schrieb: >> Hello, >> >> I am really surprised that I am asking this

Re: Attack a sacred Python Cow

2008-07-29 Thread Nikolaus Rath
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > Nikolaus Rath a écrit : >> Michael Torrie <[EMAIL PROTECTED]> writes: > > (snip) > >>> In short, unlike what most of the implicit self advocates are >>> saying, it's not just a simple change to

[unittest] Run setUp only once

2008-07-29 Thread Nikolaus Rath
Hello, I have a number of conceptually separate tests that nevertheless need a common, complicated and expensive setup. Unfortunately, unittest runs the setUp method once for each defined test, even if they're part of the same class as in class TwoTests(unittest.TestCase): def setUp(self):

Re: [unittest] Run setUp only once

2008-07-29 Thread Nikolaus Rath
Jean-Paul Calderone <[EMAIL PROTECTED]> writes: > On Tue, 29 Jul 2008 16:35:55 +0200, Nikolaus Rath <[EMAIL PROTECTED]> wrote: >>Hello, >> >>I have a number of conceptually separate tests that nevertheless need >>a common, complicated and expensive setup

Re: [unittest] Run setUp only once

2008-07-29 Thread Nikolaus Rath
Jean-Paul Calderone <[EMAIL PROTECTED]> writes: > On Tue, 29 Jul 2008 19:26:09 +0200, Nikolaus Rath <[EMAIL PROTECTED]> wrote: >>Jean-Paul Calderone <[EMAIL PROTECTED]> writes: >>> On Tue, 29 Jul 2008 16:35:55 +0200, Nikolaus Rath <[EMAIL PROTECTED]> wro

Difference between type and class

2008-07-31 Thread Nikolaus Rath
Hello, Can someone explain to me the difference between a type and a class? After reading http://www.cafepy.com/article/python_types_and_objects/ it seems to me that classes and types are actually the same thing: - both are instances of a metaclass, and the same metaclass ('type') can instant

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Thomas Troeger <[EMAIL PROTECTED]> writes: >> Can someone explain to me the difference between a type and a class? > > If your confusion is of a more general nature I suggest reading the > introduction of `Design Patterns' (ISBN-10: 0201633612), under > Specifying Object Interfaces'. > > In short:

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
oj <[EMAIL PROTECTED]> writes: > On Jul 31, 11:37 am, Nikolaus Rath <[EMAIL PROTECTED]> wrote: >> So why does Python distinguish between e.g. the type 'int' and the >> class 'myclass'? Why can't I say that 'int' is a class and 

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud <[EMAIL PROTECTED]> writes: >> > Can someone explain to me the difference between a type and a class? >> >> If your confusion is of a more general nature I suggest reading the >> introduction of `Design Patterns' (ISBN-10: 0201633612), under >> `Specifying Object Interfaces'. >> >> In

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud <[EMAIL PROTECTED]> writes: > Le Thursday 31 July 2008 14:30:19 Nikolaus Rath, vous avez écrit : >> oj <[EMAIL PROTECTED]> writes: >> > On Jul 31, 11:37 am, Nikolaus Rath <[EMAIL PROTECTED]> wrote: >> >> So why does Python distinguish

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud <[EMAIL PROTECTED]> writes: > Le Thursday 31 July 2008 16:46:28 Nikolaus Rath, vous avez écrit : >> Maric Michaud <[EMAIL PROTECTED]> writes: >> >> > Can someone explain to me the difference between a type and a class? >> >> >&

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Maric Michaud <[EMAIL PROTECTED]> writes: >>> What the means is that int is not a user type but a >>> builtin type, instances of int are not types (or classes) but common >>> objects, so its nature is the same as any classes. >>> >>> The way it prints doesn't matter, it's just the __repr__ of any

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Miles <[EMAIL PROTECTED]> writes: > On Thu, Jul 31, 2008 at 1:59 PM, Nikolaus Rath wrote: >> If it is just a matter of different rendering, what's the reason for >> doing it like that? Wouldn't it be more consistent and straightforward >> to denote builtin type

Re: Difference between type and class

2008-07-31 Thread Nikolaus Rath
Steven D'Aprano <[EMAIL PROTECTED]> writes: > So, to the Original Poster: > > In Python, new-style classes and types are the same, but it is > traditional to refer to customer objects as "class" and built-in > objects as "types". Old-style classes are different, but you are > discouraged from using

Locking around

2008-08-04 Thread Nikolaus Rath
Hello, I need to synchronize the access to a couple of hundred-thousand files[1]. It seems to me that creating one lock object for each of the files is a waste of resources, but I cannot use a global lock for all of them either (since the locked operations go over the network, this would make the

Re: Locking around

2008-08-06 Thread Nikolaus Rath
Ulrich Eckhardt <[EMAIL PROTECTED]> writes: > Nikolaus Rath wrote: >> I need to synchronize the access to a couple of hundred-thousand >> files[1]. It seems to me that creating one lock object for each of the >> files is a waste of resources, but I cannot use a glo

Re: Locking around

2008-08-06 Thread Nikolaus Rath
Nikolaus Rath <[EMAIL PROTECTED]> writes: >> This should work, at least the idea is not flawed. However, I'd say >> there are too many locks involved. Rather, you just need a simple >> flag and the global lock. Further, you need a condition/event that >> tell

Re: Locking around

2008-08-06 Thread Nikolaus Rath
Carl Banks <[EMAIL PROTECTED]> writes: > Freaky... I just posted nearly this exact solution. > > I have a couple comments. First, the call to acquire should come > before the try block. If the acquire were to fail, you wouldn't want > to release the lock on cleanup. > > Second, you need to change

Re: Locking around

2008-08-06 Thread Nikolaus Rath
Tobiah <[EMAIL PROTECTED]> writes: > On Mon, 04 Aug 2008 15:30:51 +0200, Nikolaus Rath wrote: > >> Hello, >> >> I need to synchronize the access to a couple of hundred-thousand >> files[1]. It seems to me that creating one lock object for each of the >> f

Re: Find class of an instance?

2008-08-06 Thread Nikolaus Rath
Neal Becker <[EMAIL PROTECTED]> writes: > Sounds simple, but how, given an instance, do I find the class? It does not only sound simple. When 'inst' is your instance, then inst.__class__ or type(inst) is the class. Best, -Nikolaus -- »It is not worth an intelligent man's time to

Re: Calculate sha1 hash of a binary file

2008-08-07 Thread Nikolaus Rath
LaundroMat <[EMAIL PROTECTED]> writes: > Hi - > > I'm trying to calculate unique hash values for binary files, > independent of their location and filename, and I was wondering > whether I'm going in the right direction. > > Basically, the hash values are calculated thusly: > > f = open('binaryfile

[distutils] Install script under a different name

2009-12-04 Thread Nikolaus Rath
Hello, All my Python files have extension .py. However, I would like to install scripts that are meant to be called by the user without the suffix, i.e. the file scripts/doit.py should end up as /usr/bin/doit. Apparently the scripts= option of the setup() function does not support this directly.

Re: [distutils] Install script under a different name

2009-12-05 Thread Nikolaus Rath
Lie Ryan writes: > On 12/5/2009 11:34 AM, Nikolaus Rath wrote: >> Hello, >> >> All my Python files have extension .py. However, I would like to install >> scripts that are meant to be called by the user without the suffix, i.e. >> the file scripts/doit.

Re: [distutils] Install script under a different name

2009-12-05 Thread Nikolaus Rath
Wolodja Wentland writes: > On Fri, Dec 04, 2009 at 19:34 -0500, Nikolaus Rath wrote: >> All my Python files have extension .py. However, I would like to install >> scripts that are meant to be called by the user without the suffix, i.e. >> the file scripts/doit.py should en

Determine PyArg_ParseTuple parameters at runtime?

2009-12-08 Thread Nikolaus Rath
Hello, I want to create an extension module that provides an interface to a couple of C functions that take arguments of type struct iovec, struct stat, struct flock, etc (the FUSE library, in case it matters). Now the problem is that these structures contain attributes of type fsid_t, off_t, dev

Profiling: Interpreting tottime

2010-04-07 Thread Nikolaus Rath
Hello, Consider the following function: def check_s3_refcounts(): """Check s3 object reference counts""" global found_errors log.info('Checking S3 object reference counts...') for (key, refcount) in conn.query("SELECT id, refcount FROM s3_objects"): refcount2 = conn.get

Re: Profiling: Interpreting tottime

2010-04-08 Thread Nikolaus Rath
"Gabriel Genellina" writes: > En Wed, 07 Apr 2010 18:44:39 -0300, Nikolaus Rath > escribió: > >> def check_s3_refcounts(): >> """Check s3 object reference counts""" >> >> global found_errors >> log.

Dynamically change __del__

2010-04-30 Thread Nikolaus Rath
Hi, I'm trying to be very clever: class tst(object): def destroy(self): print 'Cleaning up.' self.__del__ = lambda: None def __del__(self): raise RuntimeError('Instance destroyed without running destroy! Hell may break loose!') However, it doesn't work:

Problem with apsw and garbage collection

2009-06-11 Thread Nikolaus Rath
Hi, Please consider this example: #!/usr/bin/env python import apsw import tempfile fh = tempfile.NamedTemporaryFile() conn = apsw.Connection(fh.name) # Fill the db with some data cur = conn.cursor() datafh = open("/dev/urandom", "rb") cur.execute("CREATE TABLE foo (no INT, data BLOB)") for i

Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-12 Thread Nikolaus Rath
Nikolaus Rath writes: > Hi, > > Please consider this example: [] I think I managed to narrow down the problem a bit. It seems that when a function returns normally, its local variables are immediately destroyed. However, if the function is left due to an exception, the local variabl

Logging multiple lines

2009-06-16 Thread Nikolaus Rath
Hi, Are there any best practices for handling multi-line log messages? For example, the program, main = logging.getLogger() handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) main.addHandler(handler) main.setLev

Implementing a cache

2009-07-10 Thread Nikolaus Rath
Hello, I want to implement a caching data structure in Python that allows me to: 1. Quickly look up objects using a key 2. Keep track of the order in which the objects are accessed (most recently and least recently accessed one, not a complete history) 3. Quickly retrieve and remove the le

Re: Python docs disappointing

2009-07-31 Thread Nikolaus Rath
Carl Banks writes: >> This is one area in which Perl still whips Python... > > No way. Perl's man pages are organized so poorly there is no > ergonomic pit deep enough to offset them. Quick, what man page is the > "do" statement documented in? Of course there is: $ perldoc -f do | head

Monkeypatching an object to become callable

2009-08-09 Thread Nikolaus Rath
Hi, I want to monkeypatch an object so that it becomes callable, although originally it is not meant to be. (Yes, I think I do have a good reason to do so). But simply adding a __call__ attribute to the object apparently isn't enough, and I do not want to touch the class object (since it would mo

Profiling a Callback Function

2009-08-11 Thread Nikolaus Rath
Hello, I am trying to profile a Python program that primarily calls a C extension. From within the C extension, a callback Python function is then called concurrently in several threads. When I tried to profile this application with import c_extension def callback_fn(args): # Do all so

Re: Monkeypatching an object to become callable

2009-08-11 Thread Nikolaus Rath
Bruno Desthuilliers writes: > 7stud a écrit : > (snip) >> class Wrapper(object): >> def __init__(self, obj, func): >> self.obj = obj >> self.func = func >> >> def __call__(self, *args): >> return self.func(*args) >> >> def __getattr__(self, name): >> ret