How to use self-inspection to check for try-block

2009-03-20 Thread elmar
Hi everyone,

is there a sufficiently easy possibility for a Python function to find
out whether it has been called from a try-block or not?

try:
  print "Calling foo"
  foo()
except:
  print "Got exception"

In the example above, foo() should be able to 'see' that it was called
from a try block, allowing it to behave differently.

Can this information be obtained from the traceback/frame/code
objects, or is that too difficult?

Many thanks for your help,
Elmar
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to use self-inspection to check for try-block

2009-03-20 Thread elmar
On Mar 20, 9:44 am, Chris Rebert  wrote:
> On Fri, Mar 20, 2009 at 1:32 AM,   wrote:
> > Hi everyone,
>
> > is there a sufficiently easy possibility for a Python function to find
> > out whether it has been called from a try-block or not?
>
> > try:
> >  print "Calling foo"
> >  foo()
> > except:
> >  print "Got exception"
>
> > In the example above, foo() should be able to 'see' that it was called
> > from a try block, allowing it to behave differently.
>
> > Can this information be obtained from the traceback/frame/code
> > objects, or is that too difficult?
>
> It might be possible, but it seems like there ought to be a better way
> to accomplish your goal. Could you explain why you want to do this in
> the first place? Perhaps a better alternative can be found.

Well, foo() communicates with another application using sockets, and
an exception might occur in the other application. For performance
reasons, foo() normally returns before the other application has
finished execution, unless foo() is forced to wait for the result.
This can for example be achieved by using foo()'s return value (foo()
uses self-inspection to see if its return value is discarded or not).

I also want foo() to wait in case it's in a try block, so that the
user can catch exceptions that occur in the other application.

Thanks,
Elmar

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to use self-inspection to check for try-block

2009-03-20 Thread elmar
On Mar 20, 10:16 am, Chris Rebert  wrote:
> On Fri, Mar 20, 2009 at 2:09 AM,   wrote:
> > On Mar 20, 9:44 am, Chris Rebert  wrote:
> >> On Fri, Mar 20, 2009 at 1:32 AM,   wrote:
> >> > Hi everyone,
>
> >> > is there a sufficiently easy possibility for a Python function to find
> >> > out whether it has been called from a try-block or not?
>
> >> > try:
> >> >  print "Calling foo"
> >> >  foo()
> >> > except:
> >> >  print "Got exception"
>
> >> > In the example above, foo() should be able to 'see' that it was called
> >> > from a try block, allowing it to behave differently.
>
> >> > Can this information be obtained from the traceback/frame/code
> >> > objects, or is that too difficult?
>
> >> It might be possible, but it seems like there ought to be a better way
> >> to accomplish your goal. Could you explain why you want to do this in
> >> the first place? Perhaps a better alternative can be found.
>
> > Well, foo() communicates with another application using sockets, and
> > an exception might occur in the other application. For performance
> > reasons, foo() normally returns before the other application has
> > finished execution, unless foo() is forced to wait for the result.
> > This can for example be achieved by using foo()'s return value (foo()
> > uses self-inspection to see if its return value is discarded or not).
>
> > I also want foo() to wait in case it's in a try block, so that the
> > user can catch exceptions that occur in the other application.
>
> Is there any reason you can't just add a parameter (e.g. 'wait') to
> foo() to tell it whether to wait for the exception or not? It's
> certainly less magical than detecting `try` in the caller.
>

The system is used by people who don't know about these technical
details, and the goal is to hide the complexity from the user, without
having to explain when to add a 'wait' parameter etc.
Anyway, thanks for your time. I'll dig something out...

Ciao,
Elmar


--
http://mail.python.org/mailman/listinfo/python-list


Gentoo, Cygwin: Import Error time, cStringIO, Permission denied

2010-08-23 Thread Elmar Hinz
Hello all,

I freshly subscribed to this list, because I search a solution for a
very special problem. Is this the appropriate list?

Context
==

I try if it is possible to bootstrap Gentoo Prefix, upon the Cygwin
compatibility layer on Windows.

Gentoo Prefix is not a virtual machine but a bundle of Gentoo programs
compiled into a nonstandard directory on a host OS. IT is similar to
Cygwin itself, but compiled from sources.

I try to compile Prefix into Cygwin on Windows. This involves
compiling python. The gentoo management tool "emerge" is done in
python.

However I am not a Python programmer myself, so I have some
difficulties to understand what is going on.

Problem
==

After compiling pyhton I run into errors when I start to use it in
form of emerge. It says something like this in the logger module:

Import Error sys, os, types, time, string, cStringIO, traceback.
Permission denied.

I researched the web. One discssion told to try it on the pyhton
shell. I did the same. Only "time" and "cStringIO" are not imported.

Looking into the compiled sources i find cStringIO.dll and time.dll.
Both have the permissions 755. Hence permission to run them should be
given.

Is it a path problem? Are environment variables wrong?

I would expect in that case python would complain "Modules not found"
instead of "Permission denied".


I am at the end of my wits now.

Al
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Gentoo, Cygwin: Import Error time, cStringIO, Permission denied

2010-08-23 Thread Elmar Hinz
> Problem
> ==
>
> After compiling pyhton I run into errors when I start to use it in
> form of emerge. It says something like this in the logger module:
>
> Import Error sys, os, types, time, string, cStringIO, traceback.
> Permission denied.
>
> I researched the web. One discssion told to try it on the pyhton
> shell. I did the same. Only "time" and "cStringIO" are not imported.
>
> Looking into the compiled sources i find cStringIO.dll and time.dll.
> Both have the permissions 755. Hence permission to run them should be
> given.
>

I tried something different. I tried to run emerge with Cygwins
precompiled python.

In this case I get a related but different error:

fatal error - unable to map
\\?\F:\cygwin\lib\pyhton2.6\lib-dynload\time.dll to same address as
parent:

0x33 != 0x3A

What does this mean? Is there a naming conflict between pythons
time.dll and a time.dll of the windows system?

Al
-- 
http://mail.python.org/mailman/listinfo/python-list


SOLVED: Gentoo, Cygwin: Import Error time, cStringIO, Permission denied

2010-08-23 Thread Elmar Hinz
I seem to talk to myself. So for the archives:

This is no python thingy. It is a windows/cygwin one.

The second error message brings good search results in the web.

Search for: "cygwin, dll to same address as parent, rebaseall"

Al
-- 
http://mail.python.org/mailman/listinfo/python-list