[Twisted-Python] Wrapping blocking code
Justin Johnson
justinjohnson at fastmail.fm
Fri Jul 25 08:17:52 MDT 2003
Since I'm running on win2k (ugh!) I followed the instructions to use
win32eventreactor instead of the default posix reactor. I did read
through the docstrings, and it does mention that process calling can be
problematic. I ran the code below and got the following error. Is it
possible to get this working on windows? It is marked as semi-stable.
Man I hate windows! Unfortunately the servers I support are all windows
boxes.
C:\Python22\Lib\site-packages\twisted\internet\win32eventreactor.py:198:
Depreca
tionWarning: Foolish capitalist! Your opulent toilet will be your
undoing!!
log.logOwner.own(fd)
C:\Python22\Lib\site-packages\twisted\internet\win32eventreactor.py:213:
Depreca
tionWarning: The proletariat is victorious.
log.logOwner.disown(fd)
[snip]
from twisted.internet import protocol
from twisted.internet import win32eventreactor
win32eventreactor.install()
from twisted.internet import reactor
class MyProcessProtocol(protocol.ProcessProtocol):
finished = 0
def connectionMade(self):
self.data = ''
self.err = ''
self.transport.write("connectionMade")
def outReceived(self, data):
self.data = self.data + data
def outConnectionLost(self):
self.transport.write("outConnectionLost")
def errReceived(self, data):
self.err = self.err + data
self.transport.write("errReceived")
def errConnectionLost(self):
self.transport.write("errConnectionLost")
def inConnectionLost(self):
self.transport.write("inConnectionLost")
def processEnded(self, reason):
self.finished = 1
self.reason = reason
self.transport.write("processEnded")
exe = r"c:\program files\rational\clearcase\bin\cleartool.exe"
p = MyProcessProtocol()
reactor.spawnProcess(p, exe, [exe, "lsview", "-s"], env=None)
while not p.finished:
reactor.iterate()
[/snip]
On Wed, 23 Jul 2003 14:42:15 -0600, "Dave Smith" <dizzyd at jabber.org>
said:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Sounds to me like you want to use a deferToThread(...), to pass the
> calls off to the reactor's thread pool so they can run there without
> holding up the reactor's runloop.
>
> See also:
> http://www.itamarst.org/writings/OSCON03/twisted_internet-95.html
>
> Hope that helps. :)
>
> Diz
>
> On Wednesday, Jul 23, 2003, at 10:16 America/Denver, Justin Johnson
> wrote:
>
> > I have some code in my xmlrpc service that executes commands using
> > process.py (http://starship.python.net/crew/tmick/). The service
> > appears
> > to block this code, thus only allowing one connection to get any work
> > done at a time, at least while the commands are being executed.
> > Should I
> > be wrapping this up in a Deferred somehow to avoid blocking?
> >
> > Slowly but surely this is starting to make sense to me. Twisted rocks!
> >
> > Thanks.
> > -Justin
> >
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.1 (Darwin)
>
> iD8DBQE/HvMnYNE3chVHHsMRAplLAJ0bbnqUGSDkDz3AZPvCNTvOn1T8TgCg8nCd
> m830zVM1AnnL3fF76V1WHqY=
> =39jf
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
More information about the Twisted-Python
mailing list