Debugging - How to "step into"

gerry (archive)

Usenet Archive
Joined
Jul 17, 2001
Messages
351
Reaction score
0
Hi there,

I'm making a call to the following from a standalone ".exe":

System.Net.WebClient webClient = new WebClient;
webClient.UploadData("http://localhost//MyPage.aspx", whatever);

Does anyone know how to trigger a breakpoint in the "Page_load" method of "MyPage.aspx". I want to step into this but nothing I've tried works. Note that "Page_Load" is being called however and breakpoints work if I set them when debugging the web app itself. Thank you.
 

Andy O'Neill

Usenet Archive
Joined
Feb 15, 2005
Messages
93
Reaction score
0
Gerry said:
Hi there,

I'm making a call to the following from a standalone ".exe":

System.Net.WebClient webClient = new WebClient;
webClient.UploadData("http://localhost//MyPage.aspx", whatever);

Does anyone know how to trigger a breakpoint in the "Page_load" method of "MyPage.aspx". I want to step into this but nothing I've tried works. Note that "Page_Load" is being called however and breakpoints work if I set them when debugging the web app itself. Thank you.
The web page is going to be handled by the worker process. I have very rarely had to do something where I couldn't just debug the web page itself. As I recall you use the clr debugger to attach to the worker process. A quick google and there seem to be articles on doing this.
 

gerry (archive)

Usenet Archive
Joined
Jul 17, 2001
Messages
351
Reaction score
0
The web page is going to be handled by the worker process.
I have very rarely had to do something where I couldn't just debug the web page itself. As I recall you use the clr debugger to attach to the worker process. A quick google and there seem to be articles on doing this.

I'll look into this. Thanks for your help.
 

gerry (archive)

Usenet Archive
Joined
Jul 17, 2001
Messages
351
Reaction score
0
System.Net.WebClient webClient = new WebClient;
Hi, IMO your method is correct (i.e put a breakpoint in the web app) and you can't do otherwise.

Technically speaking you just send data to a URL. As this is not an explicit call, it would be quite difficult to have the debugger parsing the url to see this is an ASPX web app, to find out that this is on your localhost and to locate the corresponding solution etc...

Understood but there should be a way to do this. Hardcoding a "Debugger.Break" statement for instance is ignored.
 

Jeff Johnson

Usenet Archive
Joined
Jan 27, 2000
Messages
46
Reaction score
0
Understood but there should be a way to do this. Hardcoding a "Debugger.Break" statement for instance is ignored.

What you're not understanding is that the Web site is running completely independently of Visual Studio, so it is outside the scope of your debugging session. VS doesn't have "tentacles" that reach out to any and every process that's accessed by your program and step into them; you'd have to be explicitly debugging that other process as well.
 

mk

Usenet Archive
Joined
Oct 27, 2000
Messages
322
Reaction score
0
Stephen Hansen wrote:

You don't have to (and can't) refer to the class within the body. Class statements are sort of... odd. They are code which is directly executed, and the results are then passed into a metaclass/type/whatever and a class object is created. While within the class body, the class doesn't exist yet.

But you don't need it to.

Just do:

'internal_date': print_internal_date

...

Thanks, that worked. But in order to make it work I had to get rid of 'self' in print_internal_date signature, bc all other functions in tagdata have only a single argument:

class PYFileInfo(FileInfo):
'python file properties'

def print_internal_date(filename):
...

tagdata = {'compiled_fname': lambda x: x + 'c',
'size': os.path.getsize,
'internal_date': print_internal_date
}

That looks weird: a method with no 'self'. Hmm that is probably seriously wrong.

This obviously means no other method can call it like
self.print_internal_date, because self would get passed as first argument, yes?

I checked that print_internal_date can be called on an instance, so the same method can be seen as:

- class method -- when used in local scope definition like tagdata, or
- instance method -- when called from an instance or from self?

It should be called ______print_internal_date really. ;-)

I wonder if I'm not trying to make Python things it shouldn't be doing, but it's the problem at hand that is leading me into this conundrum: all other functions for tagdata use single arguments. I should probably code around that anyway..

Regards,
mk
 

gerry (archive)

Usenet Archive
Joined
Jul 17, 2001
Messages
351
Reaction score
0
What you're not understanding is that the Web site is running completely
independently of Visual Studio, so it is outside the scope of your debugging session.

I understand this clearly. Putting a "Diagnostics.Debugger.Break" statement in however should invoke the debugger or prompt the user to start the debugger (any debugger you want to attach, not necessarily VS). I've now got things working by attaching to the ASP.NET process and using a normal break point in VS itself. Thanks for everyone's help.
 

Bruno Desthuilliers

Usenet Archive
Joined
Jun 26, 2003
Messages
3,924
Reaction score
0
mk a écrit :
Stephen Hansen wrote:

> You don't have to (and can't) refer to the class within the body.
> Class statements are sort of... odd. They are code which is directly
> executed, and the results are then passed into a
> metaclass/type/whatever and a class object is created. While within
> the class body, the class doesn't exist yet.
>
> But you don't need it to.
>
> Just do:
>
...

Indeed. Using it that way, the print_internal_date will not be wrapped in a method object.

bc all other functions in
tagdata have only a single argument:

class PYFileInfo(FileInfo):
'python file properties'

def print_internal_date(filename):
...

tagdata = {'compiled_fname': lambda x: x + 'c',
'size': os.path.getsize,
'internal_date': print_internal_date
...

It's not a method.

Hmm that is probably
seriously wrong.

This obviously means no other method can call it like
self.print_internal_date, because self would get passed as first argument, yes?

Unless you make it a staticmethod.

I checked that print_internal_date can be called on an instance, so the same method

s/method/function/

can be seen as:

- class method -- when used in local scope definition like tagdata, or
- instance method -- when called from an instance or from self?

Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages.

The first thing is that the def statement *always* yield a function object. Always. If you don't believe it, try the following snippet:

class Foo(object):
def bar(self):
return "baaz"

print Foo.__dict__.keys
print type(Foo.__dict__['bar'])

So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The answer is : attribute lookup rules and the descriptor protocol.

To make a long story short, the descriptor protocol specify that, when, during an attribute lookup, a name resolves to a class attribute AND this attribute has a __get__ method, then this __get__ method is called (with either the instance or None and the class itself as arguments) and whatever it returns becomes the result of the attribute lookup. This mechanism is what provides support for computed attributes.

Now the trick is that the function type do implement the descriptor protocol. So when a function is an attribute of a class object and you try to access it as an attribute of either the class itself or an instance of the class, it's __get__ method is called with the instance (or None) and the class. Having access to itself (of course), the instance (if there's one) and the class, it's easy for it to wrap all this into a method object. Which is itself a callable object, that when called mostly inject the instance as first object in the argument's list and returns the result of calling the wrapped function object.

A (naive) implementation of the whole thing might look like this:

class method(object):
def __init__(self, func, instance, cls):
self.im_func = func
self.im_self = instance
self.im_class = cls

def __call__(self, *args, **kw):
# XXX : all sanity checks removed for readability if self.im_self:
args = (self.im_func,) + args
return self.im_func(*args, **kw)

class function(object):
# ...
def __get__(self, instance, cls):
return method(self, instance, cls)

So, what makes a function a "method" is not being defined in a class statement's body (well, not directly at least), it's that it is an attribute of the class. FWIW, the following code is perfectly legal:

class Foo(object):
pass

def func(obj):
print "obj is %s " % obj

Foo.method = func

f = Foo
f.method
Foo.method(f)
func(f)

I wonder if I'm not trying to make Python things it shouldn't be doing, but it's the problem at hand that is leading me into this conundrum: all other functions for tagdata use single arguments. I should probably code around that anyway..

Well, the simple solution is to just leave print_internal_date as a plain function instead of insisting on making it a method. Python is 100% OO in that everything is an object, but it's not a "pure" OO language, ie it doesn't require everything to happen in a method. So if all you need is a function, by all mean just use a function !-)

Now if you really need print_internal_date to be exposed as a method of PYFileInfo - like, you need polymorphic dispatch - then make it a staticmethod.

My 2 cents...
 

Bruno Desthuilliers

Usenet Archive
Joined
Jun 26, 2003
Messages
3,924
Reaction score
0
John Posner a écrit :
On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote:
>
Very nice writeup, Bruno -- thanks!

<blush />

<snip>

>
>
> def __call__(self, *args, **kw):
> # XXX : all sanity checks removed for readability
> if self.im_self:
> args = (self.im_func,) + args

In the line above, I think you meant:

args = (self.im_self,) + args

oops :?

Yes, indeed. Thanks for the correction.
 

John Posner

Usenet Archive
Joined
Feb 16, 2009
Messages
192
Reaction score
0
On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote:
Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages.

Very nice writeup, Bruno -- thanks!

<snip>

class method(object):
def __init__(self, func, instance, cls):
self.im_func = func
self.im_self = instance
self.im_class = cls

def __call__(self, *args, **kw):
# XXX : all sanity checks removed for readability if self.im_self:
args = (self.im_func,) + args

In the line above, I think you meant:

args = (self.im_self,) + args

-John
 

Arnaud Delobelle

Usenet Archive
Joined
Jul 8, 2003
Messages
1,099
Reaction score
0
Bruno Desthuilliers writes:

[...]
class Foo(object):
def bar(self):
return "baaz"

print Foo.__dict__.keys
print type(Foo.__dict__['bar'])

So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The answer is : attribute lookup rules and the descriptor protocol.

It's true of Python 2.X. In Python 3 there are no more unbound method:

Python 3.2a0 (py3k:75274, Oct 7 2009, 20:25:52)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>> class A:
... def f(self): pass
...
<function f at 0x445b28>
>> A.f is A.__dict__['f']
True
 

Ben Finney

Usenet Archive
Joined
Jun 26, 2003
Messages
2,776
Reaction score
0
Bruno Desthuilliers writes:

Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages.
[…]

Bruno, that's the first time I've understood the descriptor protocol, or even understood *why* the descriptor protocol is important.

Could you please post (a version of) this as a separate article somewhere? A weblog post, or a new thread in this forum, or in the documentation? Somewhere that web searches will find it prominently when searching for the Python descriptor protocol.

Thank you.
 

Mark Lawrence

Usenet Archive
Joined
Oct 10, 2004
Messages
1,364
Reaction score
0
Ben Finney wrote:
Bruno Desthuilliers writes:

> Mmmm... Let's try to explain the whole damn thing. It's really (and
> IMHO beautifully) simple once you get it, but I agree it's a bit
> peculiar when compared to most mainstream OO languages.
[…]

Bruno, that's the first time I've understood the descriptor protocol, or even understood *why* the descriptor protocol is important.

Could you please post (a version of) this as a separate article somewhere? A weblog post, or a new thread in this forum, or in the ...

I'll second, third and fourth this request. More please Bruno, or from anybody similarly qualified.

Thanks very much.

Mark Lawrence.
 

Bruno Desthuilliers

Usenet Archive
Joined
Jun 26, 2003
Messages
3,924
Reaction score
0
Mark Lawrence a écrit :
Ben Finney wrote:
> Bruno Desthuilliers writes:
>
>> Mmmm... Let's try to explain the whole damn thing. It's really (and
>> IMHO beautifully) simple once you get it, but I agree it's a bit
>> peculiar when compared to most mainstream OO languages.
> […]
>
> Bruno, that's the first time I've understood the descriptor protocol, or
> even understood *why* the descriptor protocol is important.
>
> Could you please post (a version of) this as a separate article ...

First, thanks Ben and Mark for the kind words...

I never tried to google for them, but there must be at least 4 previous posts here where I tried to explain the topic. Perhaps this latest attempt was better ?-) But anyway : if it's about making this text easier to find, it seems that posting it here is not the most efficient solution !-)

Anyway : I don't have a blog and don't really have enough time / motivation for blogging. Now if anyone is willing and able to host such a text on his own website / blog / whatever, I'd be happy to rework it a bit.

/wrt to have it in the documentation and the "from anybody similarly qualified", there's already a pretty comprehensive article in the official docs (well : linked from the official docs), from someone who's _way_ more qualified that I'll ever be - FWIW, everything I explained here and all my knowledge of the descriptor protocol, methods etc come from this article:

http://users.rcn.com/python/download/Descriptor.htm

But I understand it can be a bit intimidating for newcomers, so yes, perhaps a lighter introductory text could be helpful. So guys, if you think a revised version of my post would be of interest, I'll take you on words: provide the hosting, I'll provide the content !-)

B.
 

mk

Usenet Archive
Joined
Oct 27, 2000
Messages
322
Reaction score
0
Stephen Hansen wrote:
Or just leave it as a top level function where it was perfectly happy to live :)

Yes. This is probably the sanest solution anyway, because probably having many such functions to use, packing them into smth like package.utils anyway is a good idea. I'm trying mainly to learn and test-drive such solutions, not that I would be keen to use them excessively in production code.

This obviously means no other method can call it like self.print_internal_date, because self would get passed as first argument, yes?

It doesn't have to be. It could be a class method-- @classmethod does that, makes it receive 'cls' the actual class as the first argument. Or a @staticmethod, in which case it has no first-argument at all.

Ahh now I get it. Thanks! So that's the use for @staticmethod (I was wondering if there was any).
 

Patrice

Usenet Archive
Joined
Oct 5, 2003
Messages
1,923
Reaction score
0
Understood but there should be a way to do this. Hardcoding a
"Debugger.Break" statement for instance is ignored.

What if we restart fresh to understand te whole picture ? It seems to me that you are trying to debug a Windows application and that when at some point in this app, you hit a Web application you woudl like to be able to debug this web application. All this is on your dev box and projects are available. Is this correct ?

Have you tried to launch two instances of VS for each project ? In the web app, you have an option to "wait for an external request". Then run your Windows project and you'll get control in the other instance when the web app is hit.

Is this what you are looking for ? Else I would suggest coming back at the overall goal, sorry but I'm confused by those details and how you would like it to work but not sure about your overall goal...
 

Ben Finney

Usenet Archive
Joined
Jun 26, 2003
Messages
2,776
Reaction score
0
Bruno Desthuilliers writes:

perhaps a lighter introductory text could be helpful. So guys, if you think a revised version of my post would be of interest, I'll take you on words: provide the hosting, I'll provide the content !-)

Here, let me work my hosting magic: <URL:http://wiki.python.org/>.
 

Bruno Desthuilliers

Usenet Archive
Joined
Jun 26, 2003
Messages
3,924
Reaction score
0
Ben Finney a écrit :
Bruno Desthuilliers writes:

> perhaps a lighter introductory text could be helpful. So guys, if you
> think a revised version of my post would be of interest, I'll take you
> on words: provide the hosting, I'll provide the content !-)

Here, let me work my hosting magic: <URL:http://wiki.python.org/>.

Duh ! (me banging my head on the desktop)

Ok, I'll do my part of the job then !-)
 

mk

Usenet Archive
Joined
Oct 27, 2000
Messages
322
Reaction score
0
Bruno Desthuilliers wrote:
> Thanks, that worked. But in order to make it work I had to get rid of
> 'self' in print_internal_date signature

Indeed. Using it that way, the print_internal_date will not be wrapped in a method object.

Hold on! How does Python know what to wrap and what not to wrap, assuming of course programmer doesn't use @classmethod or @staticmethod? Bc self has no special significance, it's just a (strong) convention, Python can't know what's the first argument of a function supposed to be, self or regular argument, and therefore it has no way of differentiating between functions (defined in class body) designed to become methods and those that are not?

Where can I read on Python internals like this (aside from post of yours, that is)? Bc frankly skimming http://docs.python.org/reference/ didn't give me impression that a lot on the subject is there (well there's some, I found smth akin to your explanation below, although yours is way more readable)?

Thanks for explanation below -- I'm going to ask some related questions.

Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages.

The first thing is that the def statement *always* yield a function object. Always. If you don't believe it, try the following snippet:

class Foo(object):
def bar(self):
return "baaz"

print Foo.__dict__.keys
...

Just one thing here:

>>> Foo.bar
<unbound method Foo.bar>

Huh?! Why does it say 'unbound' method? Shouldn't that be bound method (bound to Foo, that is)?

So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ?

>>> type(Foo.__dict__['bar'])
<type 'function'>
>>> type(Foo.bar)
<type 'instancemethod'>

instancemethod - now that's something new.

The
answer is : attribute lookup rules and the descriptor protocol.

To make a long story short, the descriptor protocol specify that, when, during an attribute lookup, a name resolves to a class attribute AND this attribute has a __get__ method, then this __get__ method is called (with either the instance or None and the class itself as arguments)

Depending, I assume, on whether this is instance call | class method call, respectively?

Hmm why does the __get__ receive class as argument on top of instance | None? After all, when having an instance, the class can always be found by instance.__class__ ? Is this for sake of class methods?

Python is science, I gather: an answer to one question bears another 10 questions.

and whatever it returns becomes the result of the attribute lookup. This mechanism is what provides support for computed attributes.

Now the trick is that the function type do implement the descriptor protocol. So when a function is an attribute of a class object and you try to access it as an attribute of either the class itself or an instance of the class, it's __get__ method is called with the instance (or None) and the class.

Having access to itself (of course),

Quick question: how does a function access itself? Aside from rejected PEP (http://www.python.org/dev/peps/pep-3130/) I don't see the way of accessing itself outside globals (and even then how would a function know its name -- well it shouldn't care about it really, as function object doesn't care how it's labelled, right?). Or does in "real Python" func's __get__ receive its own function (func) as an argument, like in your example implementation below?

the
instance (if there's one) and the class, it's easy for it to wrap all this into a method object. Which is itself a callable object, that when called mostly inject the instance as first object in the argument's list and returns the result of calling the wrapped function object.

Aha! So that's the mechanism that makes self magically appear in an argument list! I always wondered how it worked. !!THANKS!!

My 2 cents...

Well, Bruno -- that was more like $200!

Regards,
mk
 

Steve Holden

Usenet Archive
Joined
Feb 24, 2000
Messages
4,734
Reaction score
0
mk wrote:
Bruno Desthuilliers wrote:
>> Thanks, that worked. But in order to make it work I had to get rid of
>> 'self' in print_internal_date signature
>
> Indeed. Using it that way, the print_internal_date will not be wrapped
> in a method object.

Hold on! How does Python know what to wrap and what not to wrap, assuming of course programmer doesn't use @classmethod or @staticmethod? Bc self has no special significance, it's just a (strong) convention, Python can't know what's the first argument of a function supposed to be, self or regular argument, and therefore it has no way of ...
No. The "unbound method" means it's a callable class attribute. The significance of "unbound" is that no specific instance is attached.

> So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ?

>>> type(Foo.__dict__['bar'])
<type 'function'>
>>> type(Foo.bar)
<type 'instancemethod'>

instancemethod - now that's something new.
Well "instancemethod" is just the type of the attribute. If you create a Foo instance, its bar method also has type instancemethod, even though it's a *bound* method:

>> foo = Foo
>> foo
<__main__.Foo object at 0x7ff2a16c>
>> foo.bar
<bound method Foo.bar of <__main__.Foo object at 0x7ff2a16c>>
>> type(foo.bar)
<type 'instancemethod'>

Note that it's only when the method is looked up *from an instance of the class* does the interpreter create the bound method. And remember that this is behavior that's specific to Python 2.
> The
> answer is : attribute lookup rules and the descriptor protocol.
>
> To make a long story short, the descriptor protocol specify that, when,
> during an attribute lookup, a name resolves to a class attribute AND
> this attribute has a __get__ method, then this __get__ method is called
> (with either the instance or None and the class itself as arguments)

Depending, I assume, on whether this is instance call | class method call, respectively?
Yes.

Hmm why does the __get__ receive class as argument on top of instance | None? After all, when having an instance, the class can always be found by instance.__class__ ? Is this for sake of class methods?
When Bruno wrote "... AND this attribute has a __get__ method ...", the __get__method has to be defined on the attribute's class - the interpreter won't even look at the instance when trying to resolve the reference. But inheritance, of course, means that the same __get__ method may be used by several classes, and when there is no instance the specific (sub)class in question must be identifiable. So you got that right.

Python is science, I gather: an answer to one question bears another 10 questions.
Yes, but it isn't quite "turtles all the way down". Ultimately the behavior we are discussing is hard-wired into the interpreter at the __getattribute__ level.

> and whatever it returns becomes the result of the attribute lookup. This
> mechanism is what provides support for computed attributes.
>
> Now the trick is that the function type do implement the descriptor
> protocol. So when a function is an attribute of a class object and you
> try to access it as an attribute of either the class itself or an
> instance of the class, it's __get__ method is called with the instance
> (or None) and the class.

> Having access to itself (of course),

Quick question: how does a function access itself? Aside from rejected ...
The function is an object of type function, so the lookup triggers a call to the __get__ method of the function's class, providing the instance (that is the function that is being called) as the first argument.

> the
> instance (if there's one) and the class, it's easy for it to wrap all
> this into a method object. Which is itself a callable object, that when
> called mostly inject the instance as first object in the argument's list
> and returns the result of calling the wrapped function object.

Aha! So that's the mechanism that makes self magically appear in an argument list! I always wondered how it worked. !!THANKS!!

> My 2 cents...

...
I agree, this is stuff that's hard to understand, and Bruno's explanations are most helpful.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top