<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/">
  <channel rdf:about="http://blog.gmane.org/gmane.comp.python.pyobjc.devel">
    <title>gmane.comp.python.pyobjc.devel</title>
    <link>http://blog.gmane.org/gmane.comp.python.pyobjc.devel</link>
    <description/>
    <syn:updatePeriod>hourly</syn:updatePeriod>
    <syn:updateFrequency>1</syn:updateFrequency>
    <syn:updateBase>1901-01-01T00:00+00:00</syn:updateBase>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5987"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5986"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5985"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5984"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5983"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5982"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5981"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5980"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5979"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5976"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5975"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5974"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5973"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5972"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5971"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5970"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5969"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5968"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5967"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5966"/>
      </rdf:Seq>
    </items>
    <image rdf:resource="http://gmane.org/img/gmane-25t.png"/>
    <textinput rdf:resource=""/>
  </channel>
  <image rdf:about="http://gmane.org/img/gmane-25t.png">
    <title>Gmane</title>
    <url>http://gmane.org/img/gmane-25t.png</url>
    <link>http://gmane.org</link>
  </image>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5987">
    <title>Re: Question on Bridging/Integration</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5987</link>
    <description>&lt;pre&gt;
On 21 May, 2012, at 12:54, Vincent wrote:


You have to use the Python C API to initialize the interpreter and load a script file that creates the Python class.  As an alternative you could create a plugin API and use py2app to create a plugin bundle, as described in &amp;lt;http://pyobjc.sourceforge.net/documentation/pyobjc-core/tutorial_embed/index.html&amp;gt;.


This should work, but you shouldn't call Py_Finalize.


Reloading scripts is a problem when the script defines a Objective-C class because redefining ObjC classes is something the ObjC runtime doesn't like. You could use the Python C API to create a new module for the script and use PyObject_GetAttrString(mod, "functionName") to access the callback functions. This makes it hard to forward ObjC objects to the callback function though.

What probably works it another layer of indirection: create two python scripts, one of them contains the class definition with not only the -shallRejectObject: method, but also a method for loading a script. That way you can use the implict conversion of ObjC objects to Python provided by PyObjC, and use the Python class to forward the method calls to Python functions in the script:


   class PythonClass (NSObject, objc.protocolNamed("PythonClassProtocol")):

        def loadScript_(self, scriptText):
                self.symbols = {}
                exec(scriptText, self.symbols)

       def shallRejectObject_(self, object):
               return self.symbols["shallRejectObject")(object)


This code is completely untested.



That would also work, but has a lot more overhead due to the interprocess communication.

Ronald

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Ronald Oussoren</dc:creator>
    <dc:date>2012-05-23T06:03:51</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5986">
    <title>Re: Question on Bridging/Integration</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5986</link>
    <description>&lt;pre&gt;Hi Ronald,

thanks for your quick answer!

The former actually sounds like exactly what I'd need.
Just one more question: Given that my python script is stored inside an NSString property,
what actions/functions would would I need to run before being able to instantiate one of the python clases?
After all the Python would have to have been run before I'd be be able to instantiate one of its subclasses, no?

Would something like this be the right way?

#import &amp;lt;Python.h&amp;gt;

…

&amp;lt; at &amp;gt;protocol PythonClassProtocol
&amp;lt; at &amp;gt;optional
- (BOOL)shallRejectObject:(NSObject *)object;
&amp;lt; at &amp;gt;end

…

Py_Initialize();
PyRun_SimpleString([self.script UTF8String])
Py_Finalize();

id&amp;lt;PythonClassProtocol&amp;gt; pythonObject = [[NSClassFromString(&amp;lt; at &amp;gt;"PythonClass") alloc] init];

for (id&amp;lt;PythonClassProtocol&amp;gt; object in self.objects) {
if ([pythonObject shallRejectObject:object]) {
[self rejectObject:object];
}
}

Oh and what if the user (me) runs the Python script once, edits it and runs it again?
Any conflicts to be expected, given that a class of that name (with potentially different logic, of which I'd obviously want to use the new one) has been created before?
If the latter was the case would I have to extract my filtering routine (not just the filtering method, but the entire code as seen above) into
its own NSTask being re-launched on every execution and talk to my own app via some kind of bridge of my own (Distributed Objects, what not)?

Thanks a bunch,
Vincent

On May 21, 2012, at 8:02 AM, Ronald Oussoren wrote:


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Vincent</dc:creator>
    <dc:date>2012-05-21T10:54:50</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5985">
    <title>Re: Question on Bridging/Integration</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5985</link>
    <description>&lt;pre&gt;
On 20 May, 2012, at 22:12, Vincent wrote:


Using Python from ObjC like this is suboptimal at the moment, mostly because I don't use PyObjC in that way. I'd define an stub class with the right interface in Objective-C with a subclass in Python that implements that interface. That way you can fetch the Python class using objc_lookUpClass (or the Foundation wrapper around that function), create an instance and then call the methods without getting compiler warnings.

To expose instances you have to define an API to fetch those instances.

Ronald

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Ronald Oussoren</dc:creator>
    <dc:date>2012-05-21T06:02:32</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5984">
    <title>Question on Bridging/Integration</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5984</link>
    <description>&lt;pre&gt;Hi there,

I'm new the whole PyObjC thing and have a simple document-bases app for which my goal is to all the user (personal project, so actually just me :P) to provide his/her (my) own filtering logic on a per-document basis.

I basically have an NSSet of objects which need to be filtered based on a user-provided logic.
As the logic should not be limited to rather primitive NSPredicates I'd like to provide a barebones in-app Python editor in which the user can define his/her logic.

There is however still one question that remained unanswered:
Being able to instantiate an Objective-C object from Python is neat, but still isolated. How do I expose a particular object instance from one language to the other?
After all I need to pass my Objective-C object to Python for evaluation and receive an answer from it in respose. 

A minimal sample function (as provided by the user at runtime) would look something like this:

def shallRejectObject(object)
if object.foo():
return True
return False

Being totally new to PyObjC I'm thinking of some kind of reverse "objc.lookUpClass(…)" to allow me to instantiate my Python subclass from within Objective-C. Or how else would one approach this?

Any hints?

Thanks in advance,
Vincent
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
&lt;/pre&gt;</description>
    <dc:creator>Vincent</dc:creator>
    <dc:date>2012-05-20T20:12:28</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5983">
    <title>Re: Garbage collection in Python/Pyobjc</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5983</link>
    <description>&lt;pre&gt;
Thanks for a really useful link.

N.

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
&lt;/pre&gt;</description>
    <dc:creator>Nicholas Cole</dc:creator>
    <dc:date>2012-04-16T16:44:37</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5982">
    <title>Re: Garbage collection in Python/Pyobjc</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5982</link>
    <description>&lt;pre&gt;
Does the NSAutoreleasePool object need to be called "pool"?  How do
objects created 'know' that there is a pool available?

Best wishes,

Nicholas

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
&lt;/pre&gt;</description>
    <dc:creator>Nicholas Cole</dc:creator>
    <dc:date>2012-04-16T12:59:56</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5981">
    <title>Re: Is there an Xcode Cocoa sample that calls Python?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5981</link>
    <description>&lt;pre&gt;Hi Virgil,

Thank you for your work making it possible to embed Python in Objective-C with ObjP!

I really appreciate your clear documentation and example code!

It's very encouraging to me.

Sincerely,
Joel


________________________________
 From: Virgil Dupras &amp;lt;hsoft&amp;lt; at &amp;gt;hardcoded.net&amp;gt;
To: Joel Norvell &amp;lt;frameworker&amp;lt; at &amp;gt;yahoo.com&amp;gt; 
Cc: "pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net" &amp;lt;pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net&amp;gt; 
Sent: Tuesday, April 10, 2012 6:15 AM
Subject: Re: [Pyobjc-dev] Is there an Xcode Cocoa sample that calls Python?
 

On 2012-04-10, at 3:43 AM, Joel Norvell wrote:


Hi Joel,

I wrote an article about that a couple of weeks ago. It might be a good starting point:

http://www.hardcoded.net/articles/embedding-python-in-objc.htm

There's even a link to guiskel in it. It's a sample project that does exactly that:

https://bitbucket.org/hsoft/guiskel/overview

Regards,
Virgil Dupras------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Joel Norvell</dc:creator>
    <dc:date>2012-04-11T06:08:24</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5980">
    <title>Re: Is there an Xcode Cocoa sample that calls Python?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5980</link>
    <description>&lt;pre&gt;
On 2012-04-10, at 3:43 AM, Joel Norvell wrote:


Hi Joel,

I wrote an article about that a couple of weeks ago. It might be a good starting point:

http://www.hardcoded.net/articles/embedding-python-in-objc.htm

There's even a link to guiskel in it. It's a sample project that does exactly that:

https://bitbucket.org/hsoft/guiskel/overview

Regards,
Virgil Dupras
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
&lt;/pre&gt;</description>
    <dc:creator>Virgil Dupras</dc:creator>
    <dc:date>2012-04-10T13:15:23</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5979">
    <title>Is there an Xcode Cocoa sample that calls Python?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5979</link>
    <description>&lt;pre&gt;Hi PyObjC People,


I'm interested in calling Python routines from within a Cocoa/ObjC program.

Is there a sample Xcode project that does this?

I did see Bill Bumgarner's "Calling Python from Objective-C" example and it's helpful. But I'm hoping for a Cocoa sample in an Xcode context to work from if one is available.

I realize that this isn't purely a PyObjC question but I thought this list would be a good place to ask it on.

Sincerely,
Joel
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Joel Norvell</dc:creator>
    <dc:date>2012-04-10T07:43:54</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5976">
    <title>Re: Garbage collection in Python/Pyobjc</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5976</link>
    <description>&lt;pre&gt;Hi Peter,

You’re right, this is standard Objective-C memory management issue, but thankfully its easy to fix.  Just create a new NSAutoreleasePool at the top of your loop and del it at the bottom.  As an example, here’s the processing loop from one of my projects :

        for image in images:
            pool = NSAutoreleasePool.alloc().init()
            try:
                buffers.append( self.processImage_(image) )
            finally:
                del pool


Alternatively, with the following category hack, you can use a with statement :

# Add context manager methods to NSAutoreleasePool as a category hack
class NSAutoreleasePool(objc.Category(NSAutoreleasePool)):
    def __enter__(self):
            return self
    def __exit__(self, ext, exv, extb):
            del self
            return False

James

Le 2 janv. 2012 à 21:14, Peter Bernheim a écrit :


--
James R. Eagan
Télécom–ParisTech
www.telecom-paristech.fr/~eagan

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>James Eagan</dc:creator>
    <dc:date>2012-01-02T22:01:59</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5975">
    <title>Re: Garbage collection in Python/Pyobjc</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5975</link>
    <description>&lt;pre&gt;Thanks James, this works perfect!


On Jan 2, 2012, at 5:01 PM, James Eagan wrote:



------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
&lt;/pre&gt;</description>
    <dc:creator>Peter Bernheim</dc:creator>
    <dc:date>2012-01-02T22:20:01</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5974">
    <title>Garbage collection in Python/Pyobjc</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5974</link>
    <description>&lt;pre&gt;I'm working on a script to convert each page of a large directory of pdfs to jpgs, using a version of this script:
http://files.macscripter.net/joy/files/pdflib.py

I am walking through a directory in Python, and calling the below function on each file. It seems that there is no garbage collection being performed on any of the objects being created below, and my searches through the docs don't seem to show an explicit way of performing garbage collection on these rather large objects. How to ensure that the below code, if called thousands of times within a Python loop isn't going to consume the entire system's memory?


def pdf2jpgs(pdfpath, pages_dir, resolution=72):
    """I am converting all pages of a PDF file to JPG images."""
    
    pdfdata = NSData.dataWithContentsOfFile_(pdfpath)
    pdfrep = NSPDFImageRep.imageRepWithData_(pdfdata)
    pagecount = pdfrep.pageCount()
    for i in range(0, pagecount):
        pdfrep.setCurrentPage_(i)
        pdfimage = NSImage.alloc().init()
        pdfimage.addRepresentation_(pdfrep)
        origsize = pdfimage.size()
        width, height = origsize
        pdfimage.setScalesWhenResized_(YES)
        rf = resolution / 72.0
        pdfimage.setSize_((width*rf, height*rf))
        
        tiffimg = pdfimage.TIFFRepresentation()
        bmpimg = NSBitmapImageRep.imageRepWithData_(tiffimg)
        data = bmpimg.representationUsingType_properties_(NSJPEGFileType, {NSImageCompressionFactor: 1.0})
        pagenum = i + 1
        jpgpath = "%s/pg%d.jpg" % (pages_dir, pagenum)
        if not os.path.exists(jpgpath):
            data.writeToFile_atomically_(jpgpath, False)
    return ''
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
&lt;/pre&gt;</description>
    <dc:creator>Peter Bernheim</dc:creator>
    <dc:date>2012-01-02T20:14:17</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5973">
    <title>Re: Getting a better stack trace with PyObjc possible?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5973</link>
    <description>&lt;pre&gt;
On 27 Dec, 2011, at 22:08, Marc Van Olmen wrote:


&amp;lt;http://pypi.python.org/pypi/faulthandler/&amp;gt; might be helpful for this. I haven't used it myself yet, but as that module will be part of the stdlib in python 3.3 it should work well.

This module would allow you to write code that saves a python stacktrace when a fatal error occurs, which users could then mail to you.

Ronald


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Ronald Oussoren</dc:creator>
    <dc:date>2011-12-28T08:31:32</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5972">
    <title>Re: Getting a better stack trace with PyObjc possible?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5972</link>
    <description>&lt;pre&gt;Thanks to both of you for your thoughtful answers!

I just looked at the source code of:
http://pypi.python.org/pypi/faulthandler/
This looks very interesting, it doesn't seem to have much overhead, I could
easily add this to my shipping app. This could be a very helpful tool.

Thanks again.

marc


On Wed, Dec 28, 2011 at 6:34 AM, Ronald Oussoren &amp;lt;ronaldoussoren&amp;lt; at &amp;gt;mac.com&amp;gt;wrote:

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Marc Van Olmen</dc:creator>
    <dc:date>2011-12-28T15:47:23</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5971">
    <title>Re: Getting a better stack trace with PyObjc possible?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5971</link>
    <description>&lt;pre&gt;You cannot extract the python stack trace from a Apple crash log, but could save one yourself using the faulthandler package &amp;lt;http://pypi.python.org/pypi/faulthandler/&amp;gt;. 

I have a slightly longer message in my mail.app outgoing folder, that will get send once I have full Internet connectivity again (this mail is send through webmail).

Ronald

On Dec 28, 2011, at 09:09 AM, Ken Thomases &amp;lt;ken&amp;lt; at &amp;gt;codeweavers.com&amp;gt; wrote:

On Dec 27, 2011, at 3:08 PM, Marc Van Olmen wrote:


I assume you know that "PyEval_EvalFrameEx + 21862" doesn't correspond to any particular Python code. Since Python is running as an interpreter, the Python code is purely data and doesn't correspond to any machine instructions. Therefore, the stack trace doesn't "see" it. It's only seeing the Python interpreter's functions.

So, you're asking for the crash reporter to look into the data being used by a function, not just translating the function's address to a symbol. Certainly, there's no way to coax the crash reporter to do that. Likewise, there's no way to deduce the Python code being executed just by analyzing a crash report.

Since the crash appears to be due to an over-release, you can try to get more information about the specific object using the "zombies" facilities of the frameworks. If the issue is reproducible, you can ask your users to run your app with certain environment variables set, such as:

CFZombieLevel=19 NSZombieEnabled=YES /Applications/YourApp.app/Contents/MacOS/YourApp

(I'm not actually certain that the "CFZombieLevel=19" is desirable. You might have them try with and without, if they're willing.)

That should at least cause a better diagnostic message to be printed to the console log at the time of the crash. I believe that messaging a zombie triggers a SIGTRAP these days instead of raising an exception. The latter would have been nice in that it might have been translated into a Python exception and provoked Python into dumping a backtrace. Instead, the SIGTRAP will just crash your app in a slightly different way than the above. However, you may be able to translate the SIGTRAP into a Python exception by setting a Python signal handler for SIGTRAP. That would get you a better backtrace from zombies.

By the way, you've excerpted a crash report. You may have left out some important information about the specific nature of the crash. Also, if you haven't already, you should ask your users if anything was written to the console log at the same time as the crash.

Good luck,
Ken


------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Ronald Oussoren</dc:creator>
    <dc:date>2011-12-28T11:34:31</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5970">
    <title>Re: Getting a better stack trace with PyObjc possible?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5970</link>
    <description>&lt;pre&gt;

I assume you know that "PyEval_EvalFrameEx + 21862" doesn't correspond to any particular Python code.  Since Python is running as an interpreter, the Python code is purely data and doesn't correspond to any machine instructions.  Therefore, the stack trace doesn't "see" it.  It's only seeing the Python interpreter's functions.

So, you're asking for the crash reporter to look into the data being used by a function, not just translating the function's address to a symbol.  Certainly, there's no way to coax the crash reporter to do that.  Likewise, there's no way to deduce the Python code being executed just by analyzing a crash report.

Since the crash appears to be due to an over-release, you can try to get more information about the specific object using the "zombies" facilities of the frameworks.  If the issue is reproducible, you can ask your users to run your app with certain environment variables set, such as:

CFZombieLevel=19 NSZombieEnabled=YES /Applications/YourApp.app/Contents/MacOS/YourApp

(I'm not actually certain that the "CFZombieLevel=19" is desirable.  You might have them try with and without, if they're willing.)

That should at least cause a better diagnostic message to be printed to the console log at the time of the crash.  I believe that messaging a zombie triggers a SIGTRAP these days instead of raising an exception.  The latter would have been nice in that it might have been translated into a Python exception and provoked Python into dumping a backtrace.  Instead, the SIGTRAP will just crash your app in a slightly different way than the above.  However, you may be able to translate the SIGTRAP into a Python exception by setting a Python signal handler for SIGTRAP.  That would get you a better backtrace from zombies.

By the way, you've excerpted a crash report.  You may have left out some important information about the specific nature of the crash.  Also, if you haven't already, you should ask your users if anything was written to the console log at the same time as the crash.

Good luck,
Ken


------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
&lt;/pre&gt;</description>
    <dc:creator>Ken Thomases</dc:creator>
    <dc:date>2011-12-28T08:07:45</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5969">
    <title>Getting a better stack trace with PyObjc possible?</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5969</link>
    <description>&lt;pre&gt;hi,

I looked around the web and more specific stack overflow: I was hoping if
there is something I can do to have a better stack trace from pyobjc/python.

For example my end users send me this, after a hard crash.

0 libobjc.A.dylib 0x99b51c22 (anonymous
namespace)::AutoreleasePoolPage::pop(void*) + 350
1 com.apple.CoreFoundation 0x97b2c515 _CFAutoreleasePoolPop + 53
2 com.apple.Foundation 0x96316b87 -[NSAutoreleasePool release] + 131
3 com.apple.CoreFoundation 0x97b01749 CFRelease + 169
4 _objc.so 0x04019c21 object_dealloc + 257
5 org.python.python 0x01c6e2cf subtype_dealloc + 575
6 org.python.python 0x01c3a041 frame_dealloc + 385
7 org.python.python 0x01ced87c tb_dealloc + 156
8 org.python.python 0x01ced88c tb_dealloc + 172
9 org.python.python 0x01c52179 PyDict_DelItem + 249
10 org.python.python 0x01c52251 PyDict_DelItemString + 49
11 org.python.python 0x01cb940a PyEval_EvalFrameEx + 4810
12 org.python.python 0x01cbd6a6 PyEval_EvalFrameEx + 21862
13 org.python.python 0x01cbd6a6 PyEval_EvalFrameEx + 21862
14 org.python.python 0x01cbd6a6 PyEval_EvalFrameEx + 21862
15 org.python.python 0x01cbd6a6 PyEval_EvalFrameEx + 21862
16 org.python.python 0x01cbee9d PyEval_EvalCodeEx + 2109
17 org.python.python 0x01c3ba36 function_call + 166
18 org.python.python 0x01c0a315 PyObject_Call + 85
19 org.python.python 0x01c1c8e6 instancemethod_call + 422
20 org.python.python 0x01c0a315 PyObject_Call + 85
21 org.python.python 0x01cb717e PyEval_CallObjectWithKeywords + 78
22 org.python.python 0x01cf89d6 t_bootstrap + 70
23 libsystem_c.dylib 0x957c2ed9 _pthread_start + 335
24 libsystem_c.dylib 0x957c66de thread_start + 34


Would be nice to know which method and object was called at

PyEval_EvalFrameEx + 21862

for example.

Marc
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Marc Van Olmen</dc:creator>
    <dc:date>2011-12-27T21:08:36</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5968">
    <title>Re: PyObjC and multiprocessing module</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5968</link>
    <description>&lt;pre&gt;
Sure, I can file a bug with them.  Before I do that, I'd like to try to
figure out a solution.  Here's my problem:

I'm writing a cross-platform PyGTK application.  The main thread does
windowing, and there are two secondary threads: one for USB
communication (PyUSB), and one for text to speech (pyttsx).  Although I
would prefer true multiprocessing, the GIL isn't the end of the world
here, so threading will suffice.

It currently works in Linux and Windows with threading or
multiprocessing, but fails in OS X with both.  The multiprocessing
problem makes sense, it's a limitation of Apple's Foundation and
CPython's implementation.

For threading, I feel like there is probably a way to get it to work,
but I don't fully understand it.  I have traced the pyttsx code a bit,
and found what is happening:

1) When you launch the pyttsx processing loop, it calls
AppHelper.runConsoleEventLoop()
2) The sound plays correctly
3) When the utterance is finished, pyttsx stops its processing loop by
calling AppHelper.stopEventLoop()
4) In PyObjC, stopEventLoop() checks to see if there is a valid
"currentRunLoopStopper()" -- it does not find one, but does find a valid
NSApp(), which causes it to run NSApp()._terminate_() and kill my
application.

Here's another crazy tip: "import gtk" makes pyttsx stop working even in
the main thread.  Just importing it, so its module __init__ must be
doing something.

I don't fully understand NSRunLoops and how to manage them in threads,
nor the interaction between that and Python "threads".

Here's my test code: https://gist.github.com/1447666

Do you have any ideas on what I could try to get this working?

Thanks,

Trevor


------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
&lt;/pre&gt;</description>
    <dc:creator>Trevor Bentley</dc:creator>
    <dc:date>2011-12-08T17:14:40</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5967">
    <title>Re: PyObjC and multiprocessing module</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5967</link>
    <description>&lt;pre&gt;
On 7 Dec, 2011, at 23:54, Trevor Bentley wrote:


Most of Apple's frameworks beyond the basic Unix tools require that you child proceses immediately call execv() instead of forking of a child and doing work there as multiprocessing does.

Multiprocessing uses fork+exec on windows, because those aren't separate system calls there but AFAIK you cannot force the multiprocessing library to do the same on Unix platforms.

Could you file a bug on python's tracker about the problem you ran into?  A demo program that only uses the stdlib would be great (possibly something using Tkinter), but isn't required.

Ronald


------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Ronald Oussoren</dc:creator>
    <dc:date>2011-12-08T15:06:59</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5966">
    <title>Re: PyObjC and multiprocessing module</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5966</link>
    <description>&lt;pre&gt;
You could do something other than multiprocessing module to access
another process (socket to me!).  Depends how much a problem the GIL is
for you.
&lt;/pre&gt;</description>
    <dc:creator>Aahz</dc:creator>
    <dc:date>2011-12-08T00:04:54</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5965">
    <title>PyObjC and multiprocessing module</title>
    <link>http://permalink.gmane.org/gmane.comp.python.pyobjc.devel/5965</link>
    <description>&lt;pre&gt;I found a bunch of hits for this on Google, but no answers:

I am working on a Python application that uses the multiprocessing library.
 I am trying to spawn a process and perform text-to-speech with pyttsx, but
I get the
dreaded  __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__()
 error.

Is there any way to get this working, short of switching back to threads?
 I see that the 'correct' way is to fork() and exec(), but I don't see any
way to make that compatible with the multiprocessing module's API.

Thanks,

-Trevor
------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev&amp;lt; at &amp;gt;lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
&lt;/pre&gt;</description>
    <dc:creator>Trevor Bentley</dc:creator>
    <dc:date>2011-12-07T22:54:02</dc:date>
  </item>
  <textinput rdf:about="http://search.gmane.org/?group=$group=gmane.comp.python.pyobjc.devel">
    <title>Search Engine</title>
    <description>Search the mailing list at Gmane</description>
    <name>query</name>
    <link>http://search.gmane.org/?group=$group=gmane.comp.python.pyobjc.devel</link>
  </textinput>
</rdf:RDF>

