Re: [Twisted-Python] Moving Twisted off Trac and SVN to somewhere nicer

2011-07-06 Thread Alessandro Dentella
On Tue, Jul 05, 2011 at 10:15:09PM -0400, Jasper St. Pierre wrote:
> On Tue, Jul 5, 2011 at 5:02 AM, Alessandro Dentella  wrote:
> > On Tue, Jul 05, 2011 at 03:42:04AM -0400, Jasper St. Pierre wrote:
> >> re: Mercurial, I didn't like it when I used it. If someone can tell me
> >> how to do this[3] in hg, I'd be more inclined to play along. And that
> >
> > I do this sort of things using mercurial queues. I pile up patches in a
> > queue and can subsequently navigate in the queue (hg qgoto fix_header1) and
> > fold it with a later one (hg qfold fix_header2).
> 
> Hm. So it's like quilt? 

I think so

> Are patch queues real commits (changesets,
> revisions, whatever), so I can log and blame and grep them while I'm
> working?

yes for all 3 (log, blame, grep)

> > While the queue is not yet committed I can change the commit log of a patch
> > in a simple way.

if the patch is called my_patch1:

  $ hg goto my_patch1
  $ hg qrefresh -e (open editor to change edit log)

hg qrefresh alone would just incorporate all modification to working
directory in the patch, 

before committing you can anyhow keep all patches in a separate repository
(hg qinit will initialize it for you. I personally don't use it though).

If you use such a second repository I guess you can simply share that with
other people too, but I'm not using this workflow.

> >
> >   hg qnew -f fix1 -m "this fixed issue 1"
> >   hg qnew -I debian/control -m "fix control"
> >   hg qnew -f fix1.1 -m "forgot something in issue 1"
> >   hg qgoto fix1
> >   hg qfold fix1.1  # This concatenate the 2 comments"
> >   hg qrefresh -e   # fix your comment as you like it
> >   hg qpush
> >   hg qfinish -a   # commit all queues currently applied
> 
> Neato. This requires me to be in a queue *before* I fix my patch, right?

that's simpler. Otherwise you create a second patch and subsequently fold
them toghether.

Using a third part application called qct (that works also on git and some
other I believe) you can also cherry pick single diffs in a single patch to
be incorporated in a changeset. I use this a lot to keep the changeset as
clean as possible.


[disclaimer]
I'm not an expert of git, so my comparison should not be taken
seriously. It's true that all the time I use git I find it more convoluted than
mercurial, and I always thought it was an historical heritage.


sandro
*:-)


-- 
Sandro Dentella  *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

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


Re: [Twisted-Python] Moving Twisted off Trac and SVN to somewhere nicer

2011-07-05 Thread Alessandro Dentella
On Tue, Jul 05, 2011 at 03:42:04AM -0400, Jasper St. Pierre wrote:
> re: Mercurial, I didn't like it when I used it. If someone can tell me
> how to do this[3] in hg, I'd be more inclined to play along. And that

I do this sort of things using mercurial queues. I pile up patches in a
queue and can subsequently navigate in the queue (hg qgoto fix_header1) and
fold it with a later one (hg qfold fix_header2).

While the queue is not yet committed I can change the commit log of a patch
in a simple way.

   hg qnew -f fix1 -m "this fixed issue 1"
   hg qnew -I debian/control -m "fix control"
   hg qnew -f fix1.1 -m "forgot something in issue 1"
   hg qgoto fix1
   hg qfold fix1.1  # This concatenate the 2 comments"
   hg qrefresh -e   # fix your comment as you like it
   hg qpush
   hg qfinish -a   # commit all queues currently applied


sandro
*:-)

-- 
Sandro Dentella  *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

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


Re: [Twisted-Python] test if thread is reactor's thread

2011-05-11 Thread Alessandro Dentella

thanks to both of you for the hints. My situation is so simple that i guess
a twisted.python.threadable.isInIOThread() should suffice.

sandro
*:-)

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


[Twisted-Python] test if thread is reactor's thread

2011-05-11 Thread Alessandro Dentella

Hi,


is there a way to test if the thread a function is called is the reactor's
thread?

I have a function that can be called from the main thread or from the
reactor's thread and should behave differently...


thanks


sandro
*:-)


-- 
Sandro Dentella  *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

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


Re: [Twisted-Python] Twisted and ipython

2011-01-17 Thread Alessandro Dentella
Thanks Glyph,

On Mon, Jan 17, 2011 at 12:07:42AM -0500, Glyph Lefkowitz wrote:
> > From what you say I don't know if completion is something I'd
> > get with invective of urwid.
> 
> Invective is an IRC client (with a useful text-editing widget for Twisted's 
> "insults" module).  urwid is a client library.  Completion is something that 
> you'd need to implement yourself with either of these (as is a functional 
> Python interpreter...)

ok, clear.

> twisted.protocols.telnet is old and really should not be used.  The new,
> good telnet implementation is in twisted.conch.telnet.  You can find code
> that uses this (both a runnable application and an instructive example) in
> twisted.conch.manhole_tap, which also happens to include a python
> interpreter as its application.

ok, I found demo.tac and demo_manhole.tac and will have a deeper look at them.

> > Twisted in a thread - working setup
> > ---
> > 
> > Following a hint in the ipython ml I started a second thread for twisted and
> > I'm using blockingcallFromThread to dispatch commands to the reactor:
> 
> You can do this in pretty much any interactive Python interpreter, including 
> the default one.  It's not very convenient, though :).
> 
> > What I can't understand is why I can't put "q.discover_modules()" inside
> > callWhenRunning() command: if I do that it just blocks at the first
> > iteration of the 'for' loop.

> Because callWhenRunning will schedule start_command to be run on the main
> (reactor) thread.  

mmh in my case the reactor thread in not the main one!
IPython.twistedutil.ReactorInThread does that for me

I'm calling it from the main thread, that is not the reactor's thread in my case

rit = twistedutil.ReactorInThread()
rit.setDaemon(True)
rit.start()

> (callWhenRunning may only be called _from_ the main thread, too, which it
> seems like you might not be doing).


> Since start_command is running on the main thread, when it gets around to
> blockingCallFromThread, it puts some work into the queue for the reactor
> to do, then goes to sleep forever, trusting that the main thread will do
> the work and then wake it up.  Except - oops! - it just put the main
> thread to sleep forever, so it will never wake up.
> 
> If you'd like, you can file a ticket for blockingCallFromThread to raise a
> loud, angry exception if it is invoked from the reactor thread.

Ok I think this is the turning key. I imagine that if I start the reactor in
a separate secondary thread, calling reactor.callWhenRunnning(start_command)
from the main thread makes 'start_command' be run in the reactor's
thread. At that point I can't call blockingCallFromThread from that thread,
as you pointed out. If this assumption is wrong, please let me know and I'll
go to study threads.


> (Also, in the simple example you gave, you're invoking
> blockingCallFromThread with the wrong signature; the first argument must
> be a reactor.  The rest of my explanation was based on the assumption that
> this is not the exact code you're running, since that would log a
> traceback immediately.  Or, perhaps the fact that you're calling
> callWhenRunning from a non-main thread is blowing up in some more
> insidious way and that's the real problem.)

Sorry for the confusion. This *is* the correct code but blockingCallFromThread 
is
really IPython.twsitedutil.blockingCallFromThread that wraps
twisted.internet.threads.blockingCallFromThread passing the reactor as first 
arg.

thanks again for the valuable explanation

sandro
*:-)


-- 
Sandro Dentella  *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

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


Re: [Twisted-Python] Twisted and ipython

2011-01-16 Thread Alessandro Dentella
thanks Jean-Paul for the hints,

On Sun, Jan 16, 2011 at 12:50:05AM -, exar...@twistedmatrix.com wrote:
> On 13 Jan, 11:43 pm, san...@e-den.it wrote:
> >thanks,
> >
> >short abstact: manhole is very good, thanks. But I'd need to add 
> >readline to
> >make it usable and I'd need tab-completion too.
> 
> If by "add readline" you mean handle input using the stdlib readline 
> module, you can't really do this (or, I'm sure you can, but it would 
> involve a ton of coding).  If you only mean "have some commonly useful 
> line editing features" then you have at least a couple options:

Well, in fact I intended mainly up/down arrows *and* tab-completion, like
ipython have. 

>   * invective includes a fully unit-tested line input widget (for the 
> insults widget library).  This really belongs somewhere other than 
> invective, it'd be nice if someone pushed it back into Twisted. 
> However, you can find invective at 
> svn://svn.twistedmatrix.com/svn/Twisted/sandbox/exarkun/invective/trunk 
> until that happens.
> 
>   * urwid supports Twisted and has lots of fancy things, including an 
> input editing widget.

>From what you say I don't know if completion is something I'd
get with invective of urwid.

> Also, we really should get rid of twisted.manhole, because these days 
> manhole is supposed to refer to the stuff in twisted.conch.  I'm not 
> sure if you found the latter, but from the warning you got about 
> twisted.protocols.telnet it seems like you may have only found the 
> former.

I was able to use only manhole.telnet. I wan't able to understand how to
make twisted.protocols.telnet work in the same way and was not able to fine
a demo snippet (more for completeness that else I'm still interested in
this).

On the other hand I managed to use ipython and twisted as I wanted and
everitying is working like a charm (but I still have a question that I'll
leave for next chapter).

Twisted in a thread - working setup
---

Following a hint in the ipython ml I started a second thread for twisted and
I'm using blockingcallFromThread to dispatch commands to the reactor:

proto = Domotik()
SerialPort(proto, o.opts['device'], reactor, 
baudrate=int(o.opts['baudrate']))

rit = twistedutil.ReactorInThread()
rit.setDaemon(True)
rit.start()

q = Quadro(proto, discover=False)
proto.quadro = q
q.discover_modules()

This works exactly as I wanted. I can interact with 'q' that represents a
collection of electric modules on the serial bus 


The unresolved doubt


What I can't understand is why I can't put "q.discover_modules()" inside
callWhenRunning() command: if I do that it just blocks at the first
iteration of the 'for' loop.

reactor.callWhenRunning( start_command, proto)

def start_command(proto):
q.discover_modules()

class Quadro(object):

def __init__(self, proto):
self.proto = proto
self.modules = []

def discover_modules(self):
"""send a request to the serial bus to understand which electric
modules are present"""

for x in range(10):
blockingCallFromThread(reactor.callLater, 1 + x/5.0, 
self.proto.ask_status, x)


thanks

sandro
*:-)


-- 
Sandro Dentella  *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

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


Re: [Twisted-Python] Twisted and ipython

2011-01-13 Thread Alessandro Dentella
thanks,

short abstact: manhole is very good, thanks. But I'd need to add readline to
make it usable and I'd need tab-completion too. 


On Thu, Jan 13, 2011 at 12:06:10PM +, Michael Thompson wrote:
> On 11 January 2011 07:48, Alessandro Dentella  wrote:
> 
> > So what's the suggested way to play with twisted?
> 
> It depends what you're trying to do. I'd suggest you get some form of
> skeleton program running first. 

I do have already: it uses SerialPort, queries a serial bus and returns info
on a domotic system (switches & co). Apart from my queries it also listen to
whatever the serial bus issues and react changing the internal state of some
objects.

What I'd like to do is to play interactively with these objects (Eg: a
digital module with 8 switches: I want to switch on/off the exits).

> At that point you can interact with the program using twisted manhole.

this is interesting. I found a working example::

   from twisted.internet import reactor
   from twisted.conch import telnet

   def createShellServer( ):

   print 'Creating shell server instance'
   factory = telnet.ShellFactory()
   port = reactor.listenTCP( 2000, factory)
   factory.namespace['x'] = 'hello world'
   factory.username = 'sd'
   factory.password = 'vega'
   print 'Listening on port 2000'
   return port

   if __name__ == "__main__":

   reactor.callWhenRunning( createShellServer )
   reactor.run()

that raises /usr/lib/python2.6/dist-packages/twisted/manhole/telnet.py:8: 
DeprecationWarning: As of Twisted 2.1, twisted.protocols.telnet is deprecated.  
See twisted.conch.telnet for the current, supported API.
  from twisted.protocols import telnet

I couldn't make out a correct syntax using the new API. Can somebody point
me to the correct solution?

Adding readline


To make this solution viable to me I really need to have readline and
completion. I found a thread hinting of a patch that should implement it but
no real patch to see [1].

I tryied to start an IPythonShell at the prompt but it simply hangs forever.



sandro
*:-)

[1] http://www.mail-archive.com/twisted-web@twistedmatrix.com/msg02241.html

-- 
Sandro Dentella  *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

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


[Twisted-Python] Twisted and ipython

2011-01-11 Thread Alessandro Dentella
Hi,

I'm starting a project where I plan to use twisted for the first time. I'd
like to practice using ipython and after looking around I found a recepe [1]
by Metthew Scott and a comment by Bob Ippolito on that recepe that suggests
a different approch [2].

In the ipython manual there's a reference to twisted in the -*thread
section, but it's unclear to me what should be the option (-pylab as for
matplotlib?):

-gthread, -qthread, -q4thread, -wthread, -pylab
  Only  ONE  of  these  can  be given, and it can only be given as 
the first option
  passed to IPython (it will have no effect in any other position). 
  They  provide
  threading  support  for  the  GTK,  QT3, QT4 and WXWidgets 
toolkits, for the mat-
  plotlib library and Twisted reactor.


So what's the suggested way to play with twisted?


thanks in advance
sandro
*:-)



[1] 
http://code.activestate.com/recipes/410670-integrating-twisted-reactor-with-ipython/
[2] 
http://bob.pythonmac.org/archives/2005/04/17/twisted-and-foreign-event-loops/



-- 
Sandro Dentella  *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy

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