Re: [Pyobjc-dev] runloop in non-GUI apps
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2005-03-24 17:40:36
|
On Mar 23, 2005, at 7:50 PM, Brian Granger wrote: > I am building a pyobjc application that is designed to work from an > interactive python prompt. That is, I don't create a a full fledged > GUI Cocoa application. The main thing that I am facing is that I need > to run the Cocoa runloop manually using calls to the following > function: > > def rlwait(nsec): > """Runs the current NSRunLoop for nsec seconds.""" > runLoop = NSRunLoop.currentRunLoop() > until = NSDate.dateWithTimeIntervalSinceNow_(nsec) > runLoop.runUntilDate_(until) > > I need the runloop to run because I am using Cocoa object that have > delegates and use Key-Value observation. > > This is a pain in two respects: > > 1. I have to call rlwait in various methods of my own by hand > > 2. Each time the runloop is run, the interactive session sits there > and waits. > > So, here is my question. Can the Cocoa runloop be run continuously in > one python thread, while the interactive things happen in the main > python thread? Is there any other tricks for this that I am missing? If you are just reading lines from stdin you can do that asynchronously in the same thread by using NSFileHandle with sys.stdin.fileno() Here's an example, which I just wrote and committed: http://svn.red-bean.com/pyobjc/trunk/pyobjc/Examples/Scripts/ stdinreader.py -bob |