I've been using Twisted's Perspective Broker to manage networking for my Python program. Perspective Broker allows me to run a Python program on a remote machine and perform remote method calls on an object in the Python program. It also allows me to serialize objects and transfer them over TCP.
Once I got a Perspective Broker server and client running, I wanted
to create a "Twisted Application" and run it using twistd,
the
Twisted Daemon. Two major options are:
creating a .tac file and
creating a twistd plugin. Below, I show the steps I took to create
a ...
Despite the existence of the promising
waitForDeferred/deferredGenerator and the newer
inlineCallbacks, it appears there is no way to block
while waiting for a Deferred. Brian Granger
described the problem on the Twisted mailing list:
I have a function that returns a Deferred. I need to have the result of this Deferred returned in a (apparently) blocking/synchronous manner:glyph provided ... Read more...def myfuncBlocking(): d = myfuncReturnsDeferred() ... result = return resultI need to be able to call this function like:result = myfuncBlocking()The question is how to get the result out of the Deferred() and make it *look* like myfuncBlocking() has blocked.
Twisted is pretty
cool-- it is very powerful, but I haven't had the easiest time
learning it.
Here is a simple example that runs a couple functions
periodically (at different
rates) using LoopingCall.
For more information, here are the Twisted docs for LoopingCall.
from datetime import datetime
from twisted.internet.task import LoopingCall
from twisted.internet import reactor
def hyper_task():
print "I like to run fast", datetime.now()
def tired_task():
print "I want to run slowly", datetime.now()
lc = LoopingCall(hyper_task)
lc.start(0.1)
lc2 = LoopingCall(tired_task)
lc2.start(0.5)
reactor.run()
Results:
I like to run ...Read more...
Twisted is a networking engine written in Python, that among many other things, can be used to do parallel processing. It is very big, though, so I had a hard time finding what I needed. I browsed through the Twisted Documentation and the Twisted O'Reilly book. There is also a Recipe in the Python Cookbook. However, I found Bruce Eckel's article, Concurrency with Python, Twisted, and Flex to be the most helpful. (See also Bruce Eckel's initial article on Twisted: Grokking Twisted)
Here are my notes on running Bruce Eckel's example. I removed the Flex part ...
Read more...
aws
(4)
bison_flex
(1)
blogger
(4)
c
(10)
cardstore
(5)
colinux
(2)
concurrency
(8)
conkeror
(2)
cygwin
(17)
dell
(3)
django
(31)
eclipse
(30)
emacs
(18)
email
(1)
error
(11)
gnip
(1)
json
(1)
keyboard
(3)
linux
(31)
matplotlib
(5)
mercurial
(3)
openid
(1)
personal
(4)
preferences
(4)
pyqt
(18)
python
(88)
rails
(1)
ratpoison
(3)
recursion
(1)
rsync
(3)
ruby
(2)
sql
(10)
subversion
(4)
twisted
(5)
ubuntu
(33)
untagged
(7)
urxvt
(3)
vxworks
(26)
wmii
(3)