Re: [Pythonmac-SIG] urllib2.urlopen fails in a forked daemon with a CoreFoundation error

2009-03-16 Thread Jarkko Laiho
On Sun, Mar 15, 2009 at 9:13 PM, Bill Janssen jans...@parc.com wrote:
 You need to do an exec after doing a fork.  /usr/bin/python on OS X
 is a framework build, and some (most?) of the OS X frameworks just
 don't work after doing a fork.  You have to restart with an exec.

All right, but how is this done?

I'll refer to the code I'm using:

http://code.activestate.com/recipes/278731/

The first fork happens at line 55, and the second at line 103. As
said, I really don't understand this fork/exec business so I don't
know what I should do. Which of the many exec* functions in the os
module should I run, and with what parameters? The forking without
exec already does everything I need it to do daemonizing-wise (except
satisfy CoreFoundation), so what am I trying to accomplish? What does
CF actually require me to do, and does it mess up or require further
changes in the forking methodology I'm using?

- Jarkko L.
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] How to use pythonw on Mac OS X

2009-03-16 Thread Christopher Barker

Samantha Bess wrote:
I'm hoping you can help me.  I recently purchased a screensaver called 
Paper Pilots.  When I tried to install it, a message popped up that 
said, This program needs access to the screen. Please run with 
'pythonw',.


This is no longer required for recent versions of Python.

What version of OS-X are you running? Which python? how are you starting 
the program?


-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] Python PyGame GTK SQLAlchemy on Leopard

2009-03-16 Thread Christopher Barker

Chris Van Bael wrote:

I want to port an application that runs on Linux and Windows perfectly to OSX.
We use Python 2.5, PyGame, PyGTK and SQLAlchemy for it.
Now I have a system with Leopard on it, but want to make sure what
would be the best solution to get these dependencies installed on it.
I remember reading on this mailinglist that there were some problems
with the python included in Leopard.


some, but it mostly works well -- the biggest issues to decide are:

D you want to build stand-alone executables that will run on pre-leopard 
systems?


Do the big packages you need come as binaries -- if so, for which python?

That being said, I'd go with the python from python.org -- more ups to 
date, and usually better support by third party packages.



Do I need to install another Python alongside the included python (or
should I replace it)?


Do not replace it -- the python.org python can be installed in addition 
to it, outside of system directories.



As for pyGTK -- another option is a fink or macports python -- these 
sometimes support the unix-y stuff better.


I know it's a mess!

-Chris




--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] urllib2.urlopen fails in a forked daemon with a CoreFoundation error

2009-03-16 Thread Bill Janssen
Jarkko Laiho jarkko.la...@iki.fi wrote:

 So ultimately the question is: how should the forking code in the
 recipe be modified, so that it satisfies the requirements of OS X?
 What does an actual, concrete exec() call look like in this case, and
 at what point in the code should it occur?

I don't know -- you didn't post your entire program.  Read the Wikipedia
page and follow the refs.  Here's an example:

def daemon ():

try:
pid = os.fork()
if pid  0:
sys.exit(0) # parent
except OSError, e:
msg = fork #1 failed: (%d) %s\n % (e.errno, e.strerror)
sys.stderr.write(msg)
sys.exit(1)

os.umask(0)
# now create a new session
os.setsid()
# and fork into the new session

try:
pid = os.fork()
if pid  0:
sys.exit(0) # session leader exits here
except OSError, e:
msg = fork #2 failed: (%d) %s\n % (e.errno, e.strerror)
sys.stderr.write(msg)
sys.exit(1)

# here you could make any changes you need to the env, like setting 
PYTHONPATH
env = os.environ.copy()
# figure out how to invoke the actual program
args = [sys.executable, -c,
import mycode; +
mycode.realmain()
]
os.execve(sys.executable, args, env)

   
def realmain():

start_server()

# the real main...
# this is basically just an event-handling loop

while True:
try:
asyncore.loop()
except (KeyboardInterrupt, SystemExit), x:
note(4, Exited from main loop due to exception:\n%s, 
''.join(traceback.format_exception(*sys.exc_info(
raise
except:
note(0, Exited from main loop due to exception:\n%s, 
''.join(traceback.format_exception(*sys.exc_info(


if __name__ == __main__ and (not sys.platform.lower().startswith(win)):
daemon()
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] urllib2.urlopen fails in a forked daemon with a CoreFoundation error

2009-03-16 Thread Jarkko Laiho
 What does an actual, concrete exec() call look like in this case, and
 at what point in the code should it occur?
 I don't know -- you didn't post your entire program.  Read the Wikipedia
 page and follow the refs.

I did and understood just about none of it. Way over my head. But:

 Here's an example:
 [...]
    # figure out how to invoke the actual program
    args = [sys.executable, -c,
            import mycode; +
            mycode.realmain()
            ]
    os.execve(sys.executable, args, env)
[...]

There's a technique I didn't know about. I didn't think there was any
way of making an exec() call fit the existing code, but that might
just do the trick.

I'm pretty sure I can work with that. Thanks for your patient advice!

- Jarkko L.
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] Python PyGame GTK SQLAlchemy on Leopard

2009-03-16 Thread Christopher Barker


(make sure to reply to the list, for the archives...)

Chris Van Bael wrote:

Yes, I absolutely do want to buil binaries that can run on 10.3.9 and 10.4!
This is very important.


Then you want the python.org python.



Do you have the paths for the system python and the installation from
python.org?


system python is in:
/Library/Frameworks/Python.framework/

python.org goes into:

/Library/Frameworks/Python.framework/



My problem with Mac installers is that they just ask a partition in
which to install the software.
But I want to be sure that they install the packages into the correct
python installation. (the one from python.org)


If you are using an installer, then it has to be built for the python 
you want. Most only target one -- wxPython targets both python.org and 
Apple's (for Python 2.5)


if you use easy_install or setup.py, be sure to run them with the python 
you want to use.


-Chris




--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig