Benjamin Rutt | 1 Feb 04:59
Picon

how to ensure writes to stdout via stdio.StandardIO are completed before we shutdown the reactor?

Hi twisted community,

What’s the best way to ensure writes to stdout via stdio.StandardIO
are completed before we shutdown the reactor?   The use case is to
emit an error message before we shutdown the reactor and stop our
program.  Dummy code snippet:

--------------------------------------------
#!/usr/bin/python

from twisted.internet import reactor, stdio
from twisted.protocols.basic  import LineReceiver

class StdinInteractor(LineReceiver):
  delimiter = '\n'

def go():
  stdio_proto = StdinInteractor()
  stdio.StandardIO(stdio_proto)
  stdio_proto.transport.write('did we get this message?\n')
  if 0:
    reactor.stop()
  else:
    reactor.callLater(1.0, reactor.stop)

reactor.callWhenRunning(go)
reactor.run()
--------------------------------------------

If I change ‘if 0’ to ‘if 1’, I don’t get the message on stdout.  The
(Continue reading)

exarkun | 1 Feb 07:01

Re: how to ensure writes to stdout via stdio.StandardIO are completed before we shutdown the reactor?

On 03:59 am, rutt.4 <at> osu.edu wrote:
>Hi twisted community,
>
>What’s the best way to ensure writes to stdout via stdio.StandardIO
>are completed before we shutdown the reactor?   The use case is to
>emit an error message before we shutdown the reactor and stop our
>program.  Dummy code snippet:

If you call the transport's loseConnection method, then the protocol's 
connectionLost method will be called after the output buffer is 
completely written.

Jean-Paul

_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Tenth | 1 Feb 18:09

February Twisted Sprint

Itamar has generously offered to host this month's Boston Twisted Sprint!


Thus it will be happening at his place, near Porter Square, on Saturday, February 11th, from 1:00 PM to 9:00 PM.

An evite has gone out to the usual suspects, but if you'd like to be added (or removed from) that list, or would like more information about this or other Boston Sprints, let me know!

Thanks,

- Dave
_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
月忧茗 | 3 Feb 02:43
Picon
Gravatar

help me on startService ( service.Service )

Hi, all 

I'm a new guy for twisted, 
I just study the example of finger14.tac

But,  startService not called when program running.


Please help,  thanks.


Code like bellow:


class FingerService(service.Service):

...
def startService(self):

print 'start service'
self.test_call()
service.Service.startService(self)



Noting output ,and test_call()  not called.
_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
exarkun | 3 Feb 04:05

Re: help me on startService ( service.Service )

On 01:43 am, yueyoum <at> gmail.com wrote:
>Hi, all
>
>I'm a new guy for twisted,
>I just study the example of finger14.tac
>at this page :
>http://twistedmatrix.com/documents/current/core/howto/tutorial/protocol.html
>
>But,  *startService* not called when program running.

Services are only started if they're added to the application object. 
Did you use setServiceParent to make the application object the parent 
of your service?

Jean-Paul
月忧茗 | 3 Feb 07:11
Picon
Gravatar

Re: help me on startService ( service.Service )

Thanks for reply

Yes, of course. 

I followed the turotial ,




_______________________________


class FingerService(service.Service):
    ...
    def startService(self):
        print 'start service'
        ....

application = service.Application('finger')
f = FingerService()
serviceCollection = service.IServiceCollection(application)
internet.TCPServer(9000, f.get_FingerFactory()
                            ).setServiceParent(serviceCollection)






2012/2/3 <exarkun <at> twistedmatrix.com>
On 01:43 am, yueyoum <at> gmail.com wrote:
>Hi, all
>
>I'm a new guy for twisted,
>I just study the example of finger14.tac
>at this page :
>http://twistedmatrix.com/documents/current/core/howto/tutorial/protocol.html
>
>But,  *startService* not called when program running.

Services are only started if they're added to the application object.
Did you use setServiceParent to make the application object the parent
of your service?

Jean-Paul

_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Re: help me on startService ( service.Service )

On 02/03/2012 01:11 AM, 月忧茗 wrote:
> Thanks for reply
>
> Yes, of course.
>
> I followed the turotial ,
>

And you ran the file using "twistd -y finger14.tac"? If you did it like 
that, output may not be visible since the program is daemonized by 
default. -n option will keep it from daemonizing, and then you can see 
output on stdout.

_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
exarkun | 4 Feb 00:20

Re: help me on startService ( service.Service )

On 06:11 am, yueyoum <at> gmail.com wrote:
>Thanks for reply
>
>Yes, of course.
>
>I followed the turotial ,
>
>class FingerService(service.Service):
>    ...
>    def startService(self):
>        print 'start service'
>        ....
>
>application = service.Application('finger')
>f = FingerService()
>serviceCollection = service.IServiceCollection(application)
>internet.TCPServer(9000, f.get_FingerFactory()
>                            ).setServiceParent(serviceCollection)

Notice that nowhere here does `f` get attached to `application`.  You 
need this:

    f.setServiceParent(application)

Jean-Paul
月忧茗 | 4 Feb 07:05
Picon
Gravatar

Re: help me on startService ( service.Service )


Oh,  Thanks !
It works!


application = service.Application('finger')
f = FingerService()
f.setServiceParent(application)
internet.TCPServer(9000, f.get_FingerFactory())




2012/2/4 <exarkun <at> twistedmatrix.com>
On 06:11 am, yueyoum <at> gmail.com wrote:
>Thanks for reply
>
>Yes, of course.
>
>I followed the turotial ,
>
>class FingerService(service.Service):
>    ...
>    def startService(self):
>        print 'start service'
>        ....
>
>application = service.Application('finger')
>f = FingerService()
>serviceCollection = service.IServiceCollection(application)
>internet.TCPServer(9000, f.get_FingerFactory()
>                            ).setServiceParent(serviceCollection)

Notice that nowhere here does `f` get attached to `application`.  You
need this:

   f.setServiceParent(application)

Jean-Paul

_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
月忧茗 | 4 Feb 07:12
Picon
Gravatar

Re: help me on startService ( service.Service )


Sorry,

It should be this:


application = service.Application('finger')
f = FingerService()
f.setServiceParent(application)

serviceCollection = service.IServiceCollection(application)
internet.TCPServer(9000, f.get_FingerFactory()
                            ).setServiceParent(serviceCollection)


2012/2/4 月忧茗 <yueyoum <at> gmail.com>

Oh,  Thanks !
It works!


application = service.Application('finger')
f = FingerService()
f.setServiceParent(application)
internet.TCPServer(9000, f.get_FingerFactory())




2012/2/4 <exarkun <at> twistedmatrix.com>

On 06:11 am, yueyoum <at> gmail.com wrote:
>Thanks for reply
>
>Yes, of course.
>
>I followed the turotial ,
>
>class FingerService(service.Service):
>    ...
>    def startService(self):
>        print 'start service'
>        ....
>
>application = service.Application('finger')
>f = FingerService()
>serviceCollection = service.IServiceCollection(application)
>internet.TCPServer(9000, f.get_FingerFactory()
>                            ).setServiceParent(serviceCollection)

Notice that nowhere here does `f` get attached to `application`.  You
need this:

   f.setServiceParent(application)

Jean-Paul

_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


_______________________________________________
Twisted-Python mailing list
Twisted-Python <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Gmane