WSPBus never stops by Ctrl+C, when using psyco

0 views
Skip to first unread message

Andrew Stromnov

unread,
Feb 19, 2008, 2:42:18 PM2/19/08
to cherrypy-devel
(crossposted from cherrypy-users)

Ubuntu 7.10
Python 2.5.1,
cherrypy (trunk r1894)
psyco (trunk r51624)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from cherrypy.restsrv.wspbus import Bus

import psyco
psyco.full()

if __name__ == '__main__':
bus = Bus()
bus.start()
print "started"
bus.block()

Robert Brewer

unread,
Feb 19, 2008, 2:51:15 PM2/19/08
to cherryp...@googlegroups.com
Andrew Stromnov wrote:
> Ubuntu 7.10
> Python 2.5.1,
> cherrypy (trunk r1894)
> psyco (trunk r51624)
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> from cherrypy.restsrv.wspbus import Bus
>
> import psyco
> psyco.full()
>
> if __name__ == '__main__':
> bus = Bus()
> bus.start()
> print "started"
> bus.block()

Hrmmmmm, yeah. I don't think any of the current core devs are going to
care enough to go digging into psyco's internals to find out why this
is. So as it stands, psyco will be unsupported. But if you (or anyone
else) wants to pursue it, open a ticket, throw theories around, and
submit patches, you're more than welcome.


Robert Brewer
fuma...@aminus.org

Andrew Stromnov

unread,
Feb 19, 2008, 4:46:05 PM2/19/08
to cherrypy-devel
> fuman...@aminus.org

SIGTERM and SIGHUP also doesn't work under Ubuntu Linux. Under Windows
Vista all works as expected.

After adding pure Python function (such as print 'ping') to wait()
loop in Bus() class, all signals are handled properly.

"""
http://psyco.sourceforge.net/psycoguide/bugs.html :
The compiled machine code does not include the regular polling done by
Python, meaning that a KeyboardInterrupt will not be detected before
execution comes back to the regular Python interpreter. Your program
cannot be interrupted if caught into an infinite Psyco-compiled loop.
(This could be fixed if requested.)
"""

workaround:
implicitly forbid wait() method compiling:
"""
import psyco
psyco.cannotcompile(Bus.wait)
psyco.full()
"""

Robert Brewer

unread,
Feb 19, 2008, 5:20:15 PM2/19/08
to cherryp...@googlegroups.com
Andrew Stromnov wrote:
> On Feb 19, 10:51 pm, "Robert Brewer" <fuman...@aminus.org> wrote:
> > Andrew Stromnov wrote:
> > > Ubuntu 7.10
> > > Python 2.5.1,
> > > cherrypy (trunk r1894)
> > > psyco (trunk r51624)
> >
> > > #!/usr/bin/env python
> > > # -*- coding: utf-8 -*-
> >
> > > from cherrypy.restsrv.wspbus import Bus
> >
> > > import psyco
> > > psyco.full()
> >
> > > if __name__ == '__main__':
> > > bus = Bus()
> > > bus.start()
> > > print "started"
> > > bus.block()
> >
> > Hrmmmmm, yeah. I don't think any of the current core devs are going
> > to care enough to go digging into psyco's internals to find out why
> > this is. So as it stands, psyco will be unsupported. But if you
> > (or anyone else) wants to pursue it, open a ticket, throw theories
> > around, and submit patches, you're more than welcome.
>
> SIGTERM and SIGHUP also doesn't work under Ubuntu Linux. Under Windows
> Vista all works as expected.
>
> After adding pure Python function (such as print 'ping') to wait()
> loop in Bus() class, all signals are handled properly.
>
> """
> http://psyco.sourceforge.net/psycoguide/bugs.html :
> The compiled machine code does not include the regular polling done by
> Python, meaning that a KeyboardInterrupt will not be detected before
> execution comes back to the regular Python interpreter. Your program
> cannot be interrupted if caught into an infinite Psyco-compiled loop.
> (This could be fixed if requested.)
> """
>
> workaround:
> implicitly forbid wait() method compiling:
> """
> import psyco
> psyco.cannotcompile(Bus.wait)
> psyco.full()
> """

Terrific!

So could we permanently fix the signal issue by just doing "dummy=None"
in the Bus.wait loop (with a good comment explaining why)?

And would you rather just have commit access? ;)


Robert Brewer
fuma...@aminus.org

Andrew Stromnov

unread,
Feb 19, 2008, 6:28:07 PM2/19/08
to cherrypy-devel
> fuman...@aminus.org

Unfortunatly, "dummy=None" casts to optimized bytecode. In this case
we must use something "un-optimizable", like "dummy = eval('None')".

> And would you rather just have commit access? ;)

Yes! Excellent idea! ;)

Andrew Stromnov

unread,
Feb 20, 2008, 3:54:18 AM2/20/08
to cherrypy-devel
> fuman...@aminus.org

another workaround implementation (wspbus.py, after Bus class
definition)

try:
import psyco
psyco.cannotcompile(Bus.wait)
except ImportError:
pass

PS. Later I'll try wspbus with new psyco incarnation - PyPy

Robert Brewer

unread,
Feb 20, 2008, 11:27:08 AM2/20/08
to cherryp...@googlegroups.com
Andrew Stromnov wrote:
> another workaround implementation (wspbus.py, after Bus class
> definition)
>
> try:
> import psyco
> psyco.cannotcompile(Bus.wait)
> except ImportError:
> pass

That...sounds like a lot of memory overhead if you have psyco but aren't
using it.


Robert Brewer
fuma...@aminus.org

Andrew Stromnov

unread,
Feb 22, 2008, 5:12:21 AM2/22/08
to cherrypy-devel
Reply from psyco developer (Armin Rigo):

If you have a specific non-performance-critical loop that you know
you'd
like to be interruptible, you can prevent Psyco from compiling it (see
psyco.cannotcompile()). But it's harder to find a workaround that
would
work anywhere in the program. This could be added in Psyco (with a
small performance penalty), but I'm unlikely to do that myself, having
mostly stopped working on Psyco nowaways.

Andrew Stromnov

unread,
Mar 12, 2008, 9:39:19 AM3/12/08
to cherrypy-devel
> That...sounds like a lot of memory overhead if you have psyco but aren't
> using it.

Ok, here another implementation:
"""
def wait(self, state, interval=0.1):
"""Wait for the given state."""
def _wait(self, state, interval=0.1):
while self.state != state:
time.sleep(interval)

if 'psyco' in sys.modules:
sys.modules['psyco'].cannotcompile(_wait)

_wait(self, state, interval)
"""

Additionally, cannotcompile() may be wrapped in try/except pass
statement.
Reply all
Reply to author
Forward
0 new messages