Re: [Pyobjc-dev] threading and pyobjc? (Suggestions wanted)
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2005-02-19 22:59:55
|
On Feb 19, 2005, at 5:49 PM, Joachim M=E5rtensson wrote: > Bob Ippolito wrote: > >> Sprinkling callLater and deferreds around doesn't make your code=20 >> non-blocking. defer.succeed does the callback *right then*, so it's=20= >> just a really ugly version of the code you had before. >> >> With the code you gave, I can't really make any suggestions. Where=20= >> does this code talk on a network? Why are you using Twisted? >> > I was given the impression that Twisted was the only way to use=20 > threads with the PyObjC framework. I am not after any networking, My=20= > app is strictly CPU and I/O-bound, there is no networking. All I want=20= > to do is spin of a sub-process, so that the GUI of my app won`t be=20 > blocked, ideally I want to be able to spin of another task from the=20 > menubar. It seems I have confused myself with regards to the purpose=20= > of Twisted ;). Twisted is primarily a framework for *avoiding* threads. In the case=20 of file I/O, you're basically stuck with them because there is no=20 asynchronous way to screw around with the filesystem. Twisted does=20 allow you to deal with threads in a rather nice way with deferToThread=20= -- but if that's all you're going to use Twisted for, you might as well=20= use lower level primitives. > What is the best way to keep responsiveness in the GUI, currently it=20= > is blocked for several seconds while the for-loop repeatedly calls my=20= > CPU- and file-intensive function? Is there some better way than=20 > spinning of the intensive part? As you might have guessed I am a not=20= > that experienced when it comes to threading. Your I/O intensive stuff should happen in a thread or a separate=20 process. If you're using separate processes, Twisted is probably a=20 decent way of doing it.. but using threads in this case is probably to=20= be preferred. Looking again at the code example you gave, I really have no idea=20 what's going on. There's way too much left out, so I can't really help=20= you rewrite it using threads. The original WebServicesTool uses=20 threads, so you should look at that. I would probably have written it=20= using NSThread rather than Python's threads, but it's not effectively=20 much different. -bob |