Re: [Twisted-Python] Twisted, wxPython & PyPubSub

2009-09-09 Thread Gabriel Rossetti

Arimaz SA
Ingénieur en Informatique
Av. du 24 Janvier 11
Ateliers de la Ville de Renens, Atelier 5
1020 Renens, Switzerland
www.arimaz.com
www.mydeskfriend.com
Mob: +41-(0)79-539-0069
Tel: +41-(0)21-566-7343



exar...@twistedmatrix.com wrote:
> On 02:21 pm, gabriel.rosse...@arimaz.com wrote:
>   
>> Hello everyone,
>>
>> I am using wx with twisted and pubsub (not the on in wx but the
>> independent one) to notify each one of what is going on. I was 
>> wondering
>> if I should use reactor.callFromThread to call publisher.sendMessage or
>> not? I haven't been doing that until now but I wondered if it was 
>> better to.
>> 
>
> Use reactor.callFromThread if you have code running in a non-reactor 
> thread and you want it to initiate some action in the reactor thread.
>
> So, if publisher.sendMessage is using Twisted APIs or otherwise requires 
> that it be run only in the reactor thread, and you need to use it from a 
> non-reactor thread, then use reactor.callFromThread.  Otherwise, don't.
>
> Jean-Paul
>
>   

Would you consider the wxreactor like a non-reactor thread? I haven't 
checked out the code behind PyPubSub, but it's basically the 
Observer-Pattern so when I call publisher.sendMessage(...) it iterates 
the "subscribers" (observers) and calls the functions they associated w/ 
the subscription. Those functions are both in the twisted code and the 
wx code. The Twisted code sends messages nd the wx code brings-up/hides 
dialogs or frames. In the wxdemo it does :

# look, we can use twisted calls!
reactor.callLater(2, self.twoSecondsPassed)

but doesn't use reactor.callFromThread, but unless I'm wrong 
reactor.callLater does the same thing but deferred in time. I often see 
reactor.callLater(0, myFunc) being used.

Thank you,
Gabriel



___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] FTPClient - aborting transfers

2009-09-09 Thread Matt Bennett
On Fri, Sep 4, 2009 at 2:29 PM,  wrote:
>
> On 1 Sep, 10:51 pm, m...@bennett.name wrote:
> >Hello all,
> >
> >I've got an FTPClient implementation very similar to the one at [1],
> >and I've added the ability to retrieve a file from the server with the
> >following snippet:
> >
> >class FileReceiver(Protocol):
> >    """
> >        Protocol subclass that writes received data to a local file.
> >    """
> >    def __init__(self, filename):
> >        self.file = open(filename, 'wb')
> >
> >    def dataReceived(self, data):
> >        self.file.write(data)
> >
> >receiver = FileReceiver(local_path)
> >d = ftpClient.retrieveFile(remote_path,receiver)
> >
> >I want to be able to abort the transfers if they've not completed
> >after a specific period of time. When the timeout is triggered, I call
> >ftpClient.transport.loseConnection() which seems to stop the dL on
> >line 109 of [1] from firing, but the data transfer continues until
> >completion. This is true for both storing and retrieving files.
> >
> >In the storing case, I thought that
> >twisted.protocols.basic.FileSender's stopProducing method might help,
> >but all it seems to do is trigger the errback for anyone waiting for a
> >response - the actual data transfer continues.
> >
> >How do I abort the transfer and clear the wire when the timeout fires?
>
> The DTP connection is set as the (undocumented) dtpInstance attribute on
> the FTP instance it's associated with.  You can call loseConnection on
> that object's transport and the download should stop.  It might be
> worthwhile for someone to clean this up a bit.  Does it ever make sense
> for the transfer to continue when the control channel is gone?  Even if
> so, it'd be nice to have a supported (or at least documented) way to do
> this cleanup.

The only reference to dtpInstance I can find in
twisted/protocols/ftp.py exists on the FTP class. I may be confused,
but I thought this class was the protocol for FTP servers, rather than
clients?

In my attempt to find and stop *something* on the FTPClient, I ended
up calling finish() on the IFinishableConsumer passed into
FileSender's send method. This seems to stop the transfer in the store
case, but unfortunately I'm no closer to a solution when retrieving a
file.

Am I missing something?

Thanks,
Matt.

>
> Jean-Paul
>
> ___
> Twisted-Python mailing list
> Twisted-Python@twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] IOCP reactor on Windows 2000

2009-09-09 Thread Cedric Delfosse
Hello,

Twisted Python 8.2.0 on Windows 2000 gives me this TB when I try to use
the IOCP reactor. Is it supported on this platform ? (Works very well on
Windows XP)

The instance's SvcRun() method failed 
  File "win32serviceutil.pyc", line 805, in SvcRun
  File "server-win32.pyc", line 81, in SvcDoRun
  File "twisted\internet\iocpreactor\__init__.pyc", line 8, in 
  File "twisted\internet\iocpreactor\reactor.pyc", line 19, in 
  File "twisted\internet\iocpreactor\iocpsupport.pyc", line 12, in 
  File "twisted\internet\iocpreactor\iocpsupport.pyc", line 10, in __load
  File "iocpsupport.pyx", line 242, in iocpsupport 
: Failed to initialize Winsock function vectors 

Regards,

-- 
Cedric DelfosseMandriva / Linbox
152, rue de Grigy - Technopole Metz  57070 METZ - FRANCE
tel: +33 (0)3 87 50 87 90http://mandriva.com



___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] PB/Remote Object/Deferred question

2009-09-09 Thread John Crawford
I'm trying to understand the Perspective Broker, reading over the 
on-site documentation, specifically the article:

http://twistedmatrix.com/projects/core/documentation/howto/pb-usage.html

and there is a section about the callRemote() function that I really 
don't understand :)

First, consider these three lines:

d = factory.getRootObject()
d.addCallback(lambda object: object.callRemote("echo", "hello network"))
d.addCallback(lambda echo: 'server echoed: '+echo)

Second, the documentation says, "...object.callRemote() returns a 
Deferred. Assuming the remote method was run without causing an 
exception (including an attempt to invoke an unknown method), the 
callback attached to that Deferred will be invoked with any objects 
that were returned by the remote method call."

If I read this correctly, callRemote() returns a whole new Deferred 
object, which is *not* the same as the 'd' Deferred object we already 
have. So that *new* Deferred should be the one that the next callback 
(line 3) is added to, since the next callback is based on the success 
of the callRemote(). So wouldn't these be the correct lines:

d = factory.getRootObject()
d2 = d.addCallback(lambda object: object.callRemote("echo", "hello network"))
d2.addCallback(lambda echo: 'server echoed: '+echo)


Thanks in advance for any clarification.

John C>





___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] PB/Remote Object/Deferred question

2009-09-09 Thread exarkun
On 04:39 pm, cycl...@speakeasy.net wrote:
>I'm trying to understand the Perspective Broker, reading over the
>on-site documentation, specifically the article:
>
>http://twistedmatrix.com/projects/core/documentation/howto/pb- 
>usage.html
>
>and there is a section about the callRemote() function that I really
>don't understand :)
>
>First, consider these three lines:
>
>d = factory.getRootObject()
>d.addCallback(lambda object: object.callRemote("echo", "hello 
>network"))
>d.addCallback(lambda echo: 'server echoed: '+echo)
>
>Second, the documentation says, "...object.callRemote() returns a
>Deferred. Assuming the remote method was run without causing an
>exception (including an attempt to invoke an unknown method), the
>callback attached to that Deferred will be invoked with any objects
>that were returned by the remote method call."
>
>If I read this correctly, callRemote() returns a whole new Deferred
>object, which is *not* the same as the 'd' Deferred object we already
>have. So that *new* Deferred should be the one that the next callback
>(line 3) is added to, since the next callback is based on the success
>of the callRemote(). So wouldn't these be the correct lines:
>
>d = factory.getRootObject()
>d2 = d.addCallback(lambda object: object.callRemote("echo", "hello 
>network"))
>d2.addCallback(lambda echo: 'server echoed: '+echo)

When one Deferred is returned from a callback on another Deferred, the 
two Deferreds are "chained".  This means that the result of the one 
Deferred becomes the result of the other Deferred, and callbacks added 
to the other Deferred are not run until this happens.

Additionally, Deferred.addCallback returns self, so your version of the 
code is really exactly the same as the original version.

Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] PB/Remote Object/Deferred question

2009-09-09 Thread Peter Westlake
On Wed, 09 Sep 2009 12:39 -0400, "John Crawford" 
wrote:
> I'm trying to understand the Perspective Broker, reading over the 
> on-site documentation, specifically the article:
> 
> http://twistedmatrix.com/projects/core/documentation/howto/pb-usage.html
> 
> and there is a section about the callRemote() function that I really 
> don't understand :)
> 
> First, consider these three lines:
> 
> d = factory.getRootObject()
> d.addCallback(lambda object: object.callRemote("echo", "hello network"))
> d.addCallback(lambda echo: 'server echoed: '+echo)
> 
> Second, the documentation says, "...object.callRemote() returns a 
> Deferred. Assuming the remote method was run without causing an 
> exception (including an attempt to invoke an unknown method), the 
> callback attached to that Deferred will be invoked with any objects 
> that were returned by the remote method call."
> 
> If I read this correctly, callRemote() returns a whole new Deferred 
> object, which is *not* the same as the 'd' Deferred object we already 
> have. So that *new* Deferred should be the one that the next callback 
> (line 3) is added to, since the next callback is based on the success 
> of the callRemote(). So wouldn't these be the correct lines:
> 
> d = factory.getRootObject()
> d2 = d.addCallback(lambda object: object.callRemote("echo", "hello
> network"))
> d2.addCallback(lambda echo: 'server echoed: '+echo)

Can I get in before someone else does? If I do, will I get it right?
Be kind, O wise ones!

Here goes:

d.addCallback always returns d. Remember that the callRemote is only
called once d is fired, so its result and the result of the lambda
expression are (simplifying a little) only computed after this piece
of code is long since over and done with. It just adds callback
functions (your lambda expressions) to the callback chain of d.
 
The result of each callback function is fed into the callback chain, to
be passed as parameter to the next callback.

Because the return value from the first callback is a Deferred, it is
not passed directly to the next callback. Instead processing pauses
until this new Deferred fires, and then the value it returns is passed
to the echo callback. It's a feature, and a most nifty one :-)

In summary:

factory.getRootObject returns a Deferred, d.

Two callbacks are added to d.

...time passes...

Something in the factory module finishes doing getRootObject
and passes the result ("thing", say) to d: "d.callback(thing)".

The first callback function uses it: "object.callRemote(rootThing)".

callRemote returns a new Deferred, d2.

The code of Deferred.callback spots the callback has returned
a Deferred. It puts d2 aside in a safe place, and d.callback()
returns.

...time passes...

The callRemote gets an answer, and d2 fires. It doesn't have
any callbacks (that you know about, at least) so it returns
the value.

The code of Deferred.callback that previously stashed d2
notices that it has fired, picks up the value and passes
it along the next callback in d's chain, the lambda echo.


Regards,

Peter.



___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] FTPClient - aborting transfers

2009-09-09 Thread exarkun
On 9 Sep, 01:28 pm, m...@bennett.name wrote:
>[snip]
>
>The only reference to dtpInstance I can find in
>twisted/protocols/ftp.py exists on the FTP class. I may be confused,
>but I thought this class was the protocol for FTP servers, rather than
>clients?

You're right, I wasn't thinking about clients.
>In my attempt to find and stop *something* on the FTPClient, I ended
>up calling finish() on the IFinishableConsumer passed into
>FileSender's send method. This seems to stop the transfer in the store
>case, but unfortunately I'm no closer to a solution when retrieving a
>file.
>
>Am I missing something?

It seems FTPClient doesn't really keep track of enough objects to make 
this easy.  A patch addressing this would be welcome.

Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] IOCP reactor on Windows 2000

2009-09-09 Thread exarkun
On 9 Sep, 03:28 pm, cdelfo...@mandriva.com wrote:
>Hello,
>
>Twisted Python 8.2.0 on Windows 2000 gives me this TB when I try to use
>the IOCP reactor. Is it supported on this platform ? (Works very well 
>on
>Windows XP)
>
>The instance's SvcRun() method failed
>  File "win32serviceutil.pyc", line 805, in SvcRun
>  File "server-win32.pyc", line 81, in SvcDoRun
>  File "twisted\internet\iocpreactor\__init__.pyc", line 8, in 
>  File "twisted\internet\iocpreactor\reactor.pyc", line 19, in 
>  File "twisted\internet\iocpreactor\iocpsupport.pyc", line 12, in 
>
>  File "twisted\internet\iocpreactor\iocpsupport.pyc", line 10, in 
>__load
>  File "iocpsupport.pyx", line 242, in iocpsupport
>: Failed to initialize Winsock function 
>vectors

We're currently only doing testing on Windows XP.  I know that some 
version of iocpreactor worked on Windows 2000 at some point in the past, 
but that may have been before the significant rewrite.

We're short on Windows machines for testing already - we barely have 
enough for Windows XP coverage.  If support for other platforms would be 
useful for you, there are a few (non-exclusive) things you can do:

  - Contribute patches implementing the support you're after.  This is 
tricky, since as a project we don't have access to any Windows 2000 
machines, and we're much less likely to look at patches that fix issues 
on platforms we don't have access to.  However, it's not impossible that 
such patches could be accepted.  It depends on the problem and the 
patch.

  - Contribute a slave for that platform.  Slaves need to be online most 
of the time and be able to run Buildbot and Twisted's test suite.

  - Contribute funds for us to get a machine to run such a slave.

As far as the particular error you're seeing goes, I don't really have a 
clue.  I hope that one of the people more familiar with iocpreactor will 
chime in about that.

Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Twisted, wxPython & PyPubSub

2009-09-09 Thread exarkun
On 9 Sep, 07:12 am, gabriel.rosse...@arimaz.com wrote:
>exar...@twistedmatrix.com wrote:
>>On 02:21 pm, gabriel.rosse...@arimaz.com wrote:
>>>Hello everyone,
>>>
>>>I am using wx with twisted and pubsub (not the on in wx but the
>>>independent one) to notify each one of what is going on. I was
>>>wondering
>>>if I should use reactor.callFromThread to call publisher.sendMessage 
>>>or
>>>not? I haven't been doing that until now but I wondered if it was
>>>better to.
>>
>>Use reactor.callFromThread if you have code running in a non-reactor
>>thread and you want it to initiate some action in the reactor thread.
>>
>>So, if publisher.sendMessage is using Twisted APIs or otherwise 
>>requires
>>that it be run only in the reactor thread, and you need to use it from 
>>a
>>non-reactor thread, then use reactor.callFromThread.  Otherwise, 
>>don't.
>>
>>Jean-Paul
>
>Would you consider the wxreactor like a non-reactor thread?

I'm not sure what you mean.  The "reactor thread" is the thread that 
"reactor.run()" is called in.  Even if you're using wxreactor.
>I haven't
>checked out the code behind PyPubSub, but it's basically the
>Observer-Pattern so when I call publisher.sendMessage(...) it iterates
>the "subscribers" (observers) and calls the functions they associated 
>w/
>the subscription. Those functions are both in the twisted code and the
>wx code. The Twisted code sends messages nd the wx code brings-up/hides
>dialogs or frames. In the wxdemo it does :
>
># look, we can use twisted calls!
>reactor.callLater(2, self.twoSecondsPassed)
>
>but doesn't use reactor.callFromThread, but unless I'm wrong
>reactor.callLater does the same thing but deferred in time. I often see
>reactor.callLater(0, myFunc) being used.

The wx demo doesn't do anything with threads, so it doesn't need to use 
callFromThread.  So, if you're only doing things like what the wx demo 
does, you probably don't need callFromThread either.

callLater doesn't do the same thing as callFromThread.  There might be 
some vague similarities (really the only one is that neither one calls 
the function you pass it right away), but they're for very different 
things.

Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] IOCP reactor on Windows 2000

2009-09-09 Thread Pavel Pergamenshchik
On Wed, Sep 9, 2009 at 8:28 AM, Cedric Delfosse  wrote:
> Hello,
>
> Twisted Python 8.2.0 on Windows 2000 gives me this TB when I try to use
> the IOCP reactor. Is it supported on this platform ? (Works very well on
> Windows XP)
>
> The instance's SvcRun() method failed
>  File "win32serviceutil.pyc", line 805, in SvcRun
>  File "server-win32.pyc", line 81, in SvcDoRun
>  File "twisted\internet\iocpreactor\__init__.pyc", line 8, in 
>  File "twisted\internet\iocpreactor\reactor.pyc", line 19, in 
>  File "twisted\internet\iocpreactor\iocpsupport.pyc", line 12, in 
>  File "twisted\internet\iocpreactor\iocpsupport.pyc", line 10, in __load
>  File "iocpsupport.pyx", line 242, in iocpsupport
> : Failed to initialize Winsock function vectors

iocpreactor is not supported on Windows 2000. iocpreactor relies on
ConnectEx() API. It was introduced in Windows XP. It is,
theoretically, possible to work around it, but nobody has done so.

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python