Re: Unicode problem with myt template...

2007-05-04 Thread durumdara

Hi!

I found the solution:

def _ResponseAsString(self, Resp):
ps = Resp.content[0]
ps = ps.decode('utf-8')
return ps

def _RenderContent(self, Content):
c.PageContent = Content
self._BuildMenus()
rp = render_response('/pagetemplate.myt')
return rp

def _RenderContentFromTemplate(self, Templ):
PageContent = render_response(Templ)
PageContent = self._ResponseAsString(PageContent)
return self._RenderContent(PageContent)

def _SimpleRender(self):
path = dwfmt.ToAscii('/' + self.Controller + '/' + self.Action
+ '.myt')
return self._RenderContentFromTemplate(path)


These methods working in both of WinXP_HU_Prof, and Win2K3_En_Serv
machines...

Important: it needed to convert all of the c. rendering constants
to unicode like this.

% ToUnicode(c.PageTitle) %


def ToUnicode(s, encoding = None):
'''
Converts a string to unicode.
'''
S_typ = type('')
U_typ = type(u'')
if not (type(s) in [S_typ, U_typ]):
s = str(s)
if type(s) == S_typ:
if encoding == None:
encoding = _Locale[encoding]
s = s.decode(encoding, 'replace')
return s

def ToAscii(s, encoding = None):
'''
Converts a unicode string to ascii.
'''
S_typ = type('')
U_typ = type(u'')
if not (type(s) in [S_typ, U_typ]):
s = str(s)
if type(s) == U_typ:
if encoding == None:
encoding = _Locale[encoding]
s = s.encode(encoding,'replace')
return s

dd

On May 2, 4:37 pm, durumdara [EMAIL PROTECTED] wrote:
 Hi!

 My problem is that:

 1.)

 I used modpy before pylon, and I have many template that use
 iso-8859-2 characterset.

 When I try to render some of them I got this errormessage:
 Error(UnicodeDecodeError): 'ascii' codec can't decode byte 0xc3 in
 position 51: ordinal not in range(128)
 File:   c:\python24\lib\site-packages\myghty-1.1-py2.4.egg\myghty
 \requestbuffer.py line 367
 Context:364: 
 365: if text is None:
 366: return
 367: self._top.write(unicode(text))
 368:
 369: class StrRequestBuffer(_RequestBuffer):
 370:

 How to I force myt to it use iso-8859-2 charset?
 Or I need to convert these sources to encode ansi chars to safe html
 codes?

 2.)
 How to I encode normal text to html?
 Example: my pagetitles?
 % ToHTML(c.PageTitle) %

 Thanks for your help:
 dd


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: myghty ComponentNotFound

2007-05-04 Thread Muhammad

actually I am using Pylons 0.8.2. I didn't check the latest Pylons
version error handling techniques.

I just want to show 404 on wrong URL request, and also I don't want
the pylons web application to send any email on wrong URL request. i.e

[DEFAULT]
debug = true
email_to = [EMAIL PROTECTED]
smtp_server = localhost
error_email_from = [EMAIL PROTECTED]

 just want to show 404 to user.

Can I handle the wrong URL requests using new Pylons and Paste
version?

Regards,
Muhammad Iqbal

On Apr 28, 5:06 am, Shannon -jj Behrens [EMAIL PROTECTED] wrote:
 On 4/25/07, Muhammad [EMAIL PROTECTED] wrote:





  Hi,

  Can any body help in this.

  If some body requesting a page likehttp://www.domain.com/wpad.dat, or
  any other page request which is not exist Wrong URL.

  Then my application returning .

  An Error Occurred

  500: Internal Server Error

  And I am receiving an email with subject WebApp Error:
  myghty.exception.TopLev ...

  Is that possible.
  1) To get rid of these to many emails?
  2) Can i redirect to home page when somebody requested wrong URL?
  3) Is there any other way to handle wrong URL in pylons?

  Thanks

 It sounds like something is wrong with your Pylons application.  When
 I requesthttp://myserver.com/wpad.dat, I get a 404.  Did you delete
 the stuff that handles 404s?

 -jj

 --http://jjinux.blogspot.com/


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Paster, SQLAlchemy $HOME/.python.eggs

2007-05-04 Thread askel

On May 3, 9:27 am, C.  Handel [EMAIL PROTECTED] wrote:
 When i try to start a paster-service using the --user flag i run into
 some permission problems

 I tried to use this command to start the service:

 paster serve server.ini --user=www

 Paster will create a temporary objectstore in the homedirectory of
 root. Then it will drop privileges and can't access it anymore:

 /root/.python-eggs/MySQL_python-.../_mysql.so: cannot open shared
 object file: Permission denied

 Any nice workaround except

 su - www -c paster server server.ini

 Greetings
Christoph

I always install/upgrade packages using -Z options of easy_install.
This problem is caused by needs to unpack egg files before Python can
load anything from them.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Paster, SQLAlchemy $HOME/.python.eggs

2007-05-04 Thread askel

Another way is to set environment variable PYTHON_EGG_CACHE to
something accessible by user that paster switches to after starting
the daemon.

On May 4, 7:59 am, askel [EMAIL PROTECTED] wrote:
 On May 3, 9:27 am, C.  Handel [EMAIL PROTECTED] wrote:



  When i try to start a paster-service using the --user flag i run into
  some permission problems

  I tried to use this command to start the service:

  paster serve server.ini --user=www

  Paster will create a temporary objectstore in the homedirectory of
  root. Then it will drop privileges and can't access it anymore:

  /root/.python-eggs/MySQL_python-.../_mysql.so: cannot open shared
  object file: Permission denied

  Any nice workaround except

  su - www -c paster server server.ini

  Greetings
 Christoph

 I always install/upgrade packages using -Z options of easy_install.
 This problem is caused by needs to unpack egg files before Python can
 load anything from them.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Using encoded forward slashes in a URL?

2007-05-04 Thread Evert Rol

   Hi all,

I'm having a problem with encoded forward slashes in a URL. That is,  
I need to pass an 'id' that has encoded forward slashes in its name,  
but this results in routes not being be able map the URL: apparently  
it sees another subset of paths in the URL, even with the slashes  
encoded as %2F.

As an example, this is the actual URL called:

   http://127.0.0.1:5000/finder/select/R%2F2007%2F23

and this is my routes setup, very basic:

   map.connect('error/:action/:id', controller='error')
   map.connect(':controller/:action/:id')
   map.connect('*url', controller='template', action='view')


The call never arrives at 'def select()' in 'class FinderController',  
but results in a 404. Leaving out the %2F characters works fine  
(other than that it doesn't result in the intended output from the  
controller, but well).

Is there something missing in the routes setup, or is my way of  
thinking incorrect? This should be the way to pass forward slashes to  
a URL, right?

Thanks,

   Evert


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: myghty ComponentNotFound

2007-05-04 Thread Shannon -jj Behrens

0.8.2 seems like such a long time ago, that I can't even remember
what's been fixed.  You can check the changelogs.  Maybe someone else
remembers.

Best Regards,
-jj

On 5/4/07, Muhammad [EMAIL PROTECTED] wrote:

 actually I am using Pylons 0.8.2. I didn't check the latest Pylons
 version error handling techniques.

 I just want to show 404 on wrong URL request, and also I don't want
 the pylons web application to send any email on wrong URL request. i.e

 [DEFAULT]
 debug = true
 email_to = [EMAIL PROTECTED]
 smtp_server = localhost
 error_email_from = [EMAIL PROTECTED]

  just want to show 404 to user.

 Can I handle the wrong URL requests using new Pylons and Paste
 version?

 Regards,
 Muhammad Iqbal

 On Apr 28, 5:06 am, Shannon -jj Behrens [EMAIL PROTECTED] wrote:
  On 4/25/07, Muhammad [EMAIL PROTECTED] wrote:
 
 
 
 
 
   Hi,
 
   Can any body help in this.
 
   If some body requesting a page likehttp://www.domain.com/wpad.dat, or
   any other page request which is not exist Wrong URL.
 
   Then my application returning .
 
   An Error Occurred
 
   500: Internal Server Error
 
   And I am receiving an email with subject WebApp Error:
   myghty.exception.TopLev ...
 
   Is that possible.
   1) To get rid of these to many emails?
   2) Can i redirect to home page when somebody requested wrong URL?
   3) Is there any other way to handle wrong URL in pylons?
 
   Thanks
 
  It sounds like something is wrong with your Pylons application.  When
  I requesthttp://myserver.com/wpad.dat, I get a 404.  Did you delete
  the stuff that handles 404s?
 
  -jj
 
  --http://jjinux.blogspot.com/


 



-- 
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Unicode problem with myt template...

2007-05-04 Thread Shannon -jj Behrens

I'm glad to hear you found the solution :)

By the way:

   S_typ = type('')
   U_typ = type(u'')
   if not (type(s) in [S_typ, U_typ]):

can more easily be written:

if not isinstance(s, basestring):

Best Regards,
-jj

On 5/4/07, durumdara [EMAIL PROTECTED] wrote:

 Hi!

 I found the solution:

 def _ResponseAsString(self, Resp):
 ps = Resp.content[0]
 ps = ps.decode('utf-8')
 return ps

 def _RenderContent(self, Content):
 c.PageContent = Content
 self._BuildMenus()
 rp = render_response('/pagetemplate.myt')
 return rp

 def _RenderContentFromTemplate(self, Templ):
 PageContent = render_response(Templ)
 PageContent = self._ResponseAsString(PageContent)
 return self._RenderContent(PageContent)

 def _SimpleRender(self):
 path = dwfmt.ToAscii('/' + self.Controller + '/' + self.Action
 + '.myt')
 return self._RenderContentFromTemplate(path)


 These methods working in both of WinXP_HU_Prof, and Win2K3_En_Serv
 machines...

 Important: it needed to convert all of the c. rendering constants
 to unicode like this.

 % ToUnicode(c.PageTitle) %


 def ToUnicode(s, encoding = None):
 '''
 Converts a string to unicode.
 '''
 S_typ = type('')
 U_typ = type(u'')
 if not (type(s) in [S_typ, U_typ]):
 s = str(s)
 if type(s) == S_typ:
 if encoding == None:
 encoding = _Locale[encoding]
 s = s.decode(encoding, 'replace')
 return s

 def ToAscii(s, encoding = None):
 '''
 Converts a unicode string to ascii.
 '''
 S_typ = type('')
 U_typ = type(u'')
 if not (type(s) in [S_typ, U_typ]):
 s = str(s)
 if type(s) == U_typ:
 if encoding == None:
 encoding = _Locale[encoding]
 s = s.encode(encoding,'replace')
 return s

 dd

 On May 2, 4:37 pm, durumdara [EMAIL PROTECTED] wrote:
  Hi!
 
  My problem is that:
 
  1.)
 
  I used modpy before pylon, and I have many template that use
  iso-8859-2 characterset.
 
  When I try to render some of them I got this errormessage:
  Error(UnicodeDecodeError): 'ascii' codec can't decode byte 0xc3 in
  position 51: ordinal not in range(128)
  File:   c:\python24\lib\site-packages\myghty-1.1-py2.4.egg\myghty
  \requestbuffer.py line 367
  Context:364: 
  365: if text is None:
  366: return
  367: self._top.write(unicode(text))
  368:
  369: class StrRequestBuffer(_RequestBuffer):
  370:
 
  How to I force myt to it use iso-8859-2 charset?
  Or I need to convert these sources to encode ansi chars to safe html
  codes?
 
  2.)
  How to I encode normal text to html?
  Example: my pagetitles?
  % ToHTML(c.PageTitle) %
 
  Thanks for your help:
  dd


 



-- 
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: lowercased response headers

2007-05-04 Thread kai

This was a bug in my head(which seems to be the source of most of
them).  I
should have known better than to run off on a wild header case goose
chase. My
web development work has been infrequent the last few years.
I'm guessing from JJ's response he's wondering what I'm up to with
this funkyheader :) ?
I have some large files 500MB+ I serve out of an app running pylons
behind lighttpd. My access control/meta data/versioning  code is over
in pylons
but but serving files that size via proxy or fastcgi has been bad.
The header
 X-LIGHTTPD-send-file: /Users/kai/Documents/vimbook-OPL.pdf
 is an instruction to lighttpd to toss the body of  the response
returned by the
upstream server (pylons in this case) and instead serve the file from
disk.
This sped things way up for me. The source of the problem ended up
being that I
needed to send a content length or lighttpd refused to take action on
the
header. It didn't matter what I set the value of the header to be as
long as I
set it to a number (-1, 536870912, ... ). Sorry this is not very
pylons related
but I figured someone serving large files from a pylons/wsgi app might
find
this info useful.

Kai



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Pylons and Rights to Objects...

2007-05-04 Thread kai

I use a metaclass to set a require attribute on all methods of a class
that I define in a  dictionary (PermissionIndex)

PermissionIndex = {
,'setatime': ['time']
,'setctime': ['time']
,'setmtime': ['time']
,'getsize':  ['visible','read']
,'getcwd':   ['visible','read']
,'listdir':  ['visible','read']
,'rmdir':['visible','read','write']
,'remove':   ['visible','read','write']
,'unlink':   ['visible','read','write']
,'stat': ['visible','read']
,'chown':['perm']
,'chgrp':['perm']
,'set_group_perms':  ['perm']
,'write_lock':  ['wlock']
,'read_lock':  ['rlock']
,'incr_version':['rlock',wlock','version']

class ACLRequirementDecorator(type):
'''
utility metaclass for setting the storage method acl requirements
from a dictionary.
'''
def __init__(cls, name, bases, dict):
super(ACLRequirementDecorator, cls).__init__(name, bases,
dict)
for k,v in dict.items():
if type(v) == type(lambda x:x):
   if k in PermissionIndex.keys():
   setattr(v,'require',PermissionIndex[k])
   else:
   setattr(v,'require',[])


class BaseStorage:
__metaclass__ = ACLRequirementDecorator


def __init__(self):
pass

.


I really like the way this separates the authorizer, the object doing
the work, and the storage of access control requirements.
I have several apps where I have to hook into ldap for
somethings,mysql for others, etc ... and this approach has worked well
for me.
Credits: The inspiration for that metaclass comes from somewhere I
can't recall now. Metaclasses still make me a little dizzy.

I use this with pylons but also in several other contexts.

Have a great day!

Kai


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Webhelpers' h.link_to(_remote) escapes my URL :(

2007-05-04 Thread Christoph Haas

Dear list...

I have created a URL using information from Routes using h.url_for().
Example:

/start/page?page_nr=1called=back

Now I want to create a link to this URL with h.link_to. What I get is:

a href=/start/page?page_nr=1amp;called=backfoo/a

Apparently '' is escaped to 'amp;' which is what I obviously don't
want. Of course in the case of h.link_to I could just create the
a href=... link myself. But my actual code uses h.link_to_remote which
is a bit more complicated and I'd like to use the webhelpers for it.

I looked into the Webhelpers sources and saw that the URL is not escaped
if it's callable(). What does that mean? And what would be the correct
way to just pass the URL through?

Cheers
 Christoph


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Using Mako templates

2007-05-04 Thread voltron

Hi,

I´ll like to use only Mako templates in my projects, apart from
stating this in the middleware.py, do I have to change these lines in
the einviroment.py:

 # The following template options are passed to your template engines
tmpl_options = {}
tmpl_options['myghty.log_errors'] = True
tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link,
s=webhelpers.simple_format)


Thanks


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Paster, SQLAlchemy $HOME/.python.eggs

2007-05-04 Thread C. Handel

On May 4, 2:09 pm, askel [EMAIL PROTECTED] wrote:
 Another way is to set environment variable PYTHON_EGG_CACHE to
 something accessible by user that paster switches to after starting
 the daemon.

sounds good. Thanks.

Greetings
   Christoph


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Webhelpers' h.link_to(_remote) escapes my URL :(

2007-05-04 Thread Shannon -jj Behrens

On 5/4/07, Christoph Haas [EMAIL PROTECTED] wrote:

 Dear list...

 I have created a URL using information from Routes using h.url_for().
 Example:

 /start/page?page_nr=1called=back

 Now I want to create a link to this URL with h.link_to. What I get is:

 a href=/start/page?page_nr=1amp;called=backfoo/a

 Apparently '' is escaped to 'amp;' which is what I obviously don't
 want. Of course in the case of h.link_to I could just create the
 a href=... link myself. But my actual code uses h.link_to_remote which
 is a bit more complicated and I'd like to use the webhelpers for it.

 I looked into the Webhelpers sources and saw that the URL is not escaped
 if it's callable(). What does that mean? And what would be the correct
 way to just pass the URL through?

It's doing the right thing.  Have a look at my blog post here:

http://jjinux.blogspot.com/2006/03/html-escaping-s-in-urls-in-html.html

Best Regards,
-jj

-- 
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Spawning a worker thread from the controller?

2007-05-04 Thread Matt

Hi, I have a pylons app which I want to spawn a long-running process
from.  While this process is running (might be an hour or so), I want
the page that kicked off this process to just display status (maybe
referesh ever 30 seconds or so)...  Does anyone have some pointers on
how this should be done or what packages I should be looking into?

thx

Matt


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Spawning a worker thread from the controller?

2007-05-04 Thread Shannon -jj Behrens

On 5/4/07, Matt [EMAIL PROTECTED] wrote:
 Hi, I have a pylons app which I want to spawn a long-running process
 from.  While this process is running (might be an hour or so), I want
 the page that kicked off this process to just display status (maybe
 referesh ever 30 seconds or so)...  Does anyone have some pointers on
 how this should be done or what packages I should be looking into?

I've done this before, but not in Pylons.  Spawning a long running
process or thread is fine.  Watch out for Paste because I think Ian
put in some code to watch for runaway threads--it's probably fine.
Use a timer and AJAX to have the Web page poll the server to see if
the work is done.  (You could use Comet, but polling is probably fine.
 Ignore this statement if you don't know what I'm talking about.)  In
the best case, you can use a progress bar on the page.  Just work your
way through it; I'm sure you'll be fine.

Best Regards,
-jj

-- 
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Spawning a worker thread from the controller?

2007-05-04 Thread Matt Billenstein

On Fri, May 04, 2007 at 05:27:42PM -0700, Shannon -jj Behrens wrote:
 On 5/4/07, Matt [EMAIL PROTECTED] wrote:
  Hi, I have a pylons app which I want to spawn a long-running process
  from.  While this process is running (might be an hour or so), I want
  the page that kicked off this process to just display status (maybe
  referesh ever 30 seconds or so)...  Does anyone have some pointers on
  how this should be done or what packages I should be looking into?
 
 I've done this before, but not in Pylons.  Spawning a long running
 process or thread is fine.  Watch out for Paste because I think Ian
 put in some code to watch for runaway threads--it's probably fine.
 Use a timer and AJAX to have the Web page poll the server to see if
 the work is done.  (You could use Comet, but polling is probably fine.
  Ignore this statement if you don't know what I'm talking about.)  In
 the best case, you can use a progress bar on the page.  Just work your
 way through it; I'm sure you'll be fine.

Any recommendations on passing status between the worker thread and the
controller when it's polling?  I tried just using class variables, but
they don't seem to get updated between the threads...

thx

m

-- 
Matt Billenstein
[EMAIL PROTECTED]
http://www.vazor.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Spawning a worker thread from the controller?

2007-05-04 Thread Shannon -jj Behrens

On 5/4/07, Matt Billenstein [EMAIL PROTECTED] wrote:

 On Fri, May 04, 2007 at 05:27:42PM -0700, Shannon -jj Behrens wrote:
  On 5/4/07, Matt [EMAIL PROTECTED] wrote:
   Hi, I have a pylons app which I want to spawn a long-running process
   from.  While this process is running (might be an hour or so), I want
   the page that kicked off this process to just display status (maybe
   referesh ever 30 seconds or so)...  Does anyone have some pointers on
   how this should be done or what packages I should be looking into?
 
  I've done this before, but not in Pylons.  Spawning a long running
  process or thread is fine.  Watch out for Paste because I think Ian
  put in some code to watch for runaway threads--it's probably fine.
  Use a timer and AJAX to have the Web page poll the server to see if
  the work is done.  (You could use Comet, but polling is probably fine.
   Ignore this statement if you don't know what I'm talking about.)  In
  the best case, you can use a progress bar on the page.  Just work your
  way through it; I'm sure you'll be fine.

 Any recommendations on passing status between the worker thread and the
 controller when it's polling?  I tried just using class variables, but
 they don't seem to get updated between the threads...

How were you updating the class variable?  ClassName.variable = foo?
 If you do self.variable = foo, you're shadowing the class variable.
 By the way, naturally, watch out for race conditions.  Another option
is to use the queue module and have the worker thread push messages
onto the queue, and the controller can read messages from the queue.
I tend to prefer message queues over explicit lock management.

Best Regards,
-jj

-- 
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Spawning a worker thread from the controller?

2007-05-04 Thread Alberto Valverde


On May 5, 2007, at 2:59 AM, Shannon -jj Behrens wrote:


 On 5/4/07, Matt Billenstein [EMAIL PROTECTED] wrote:

 On Fri, May 04, 2007 at 05:27:42PM -0700, Shannon -jj Behrens wrote:
 On 5/4/07, Matt [EMAIL PROTECTED] wrote:
 Hi, I have a pylons app which I want to spawn a long-running  
 process
 from.  While this process is running (might be an hour or so), I  
 want
 the page that kicked off this process to just display status (maybe
 referesh ever 30 seconds or so)...  Does anyone have some  
 pointers on
 how this should be done or what packages I should be looking into?

 I've done this before, but not in Pylons.  Spawning a long running
 process or thread is fine.  Watch out for Paste because I think Ian
 put in some code to watch for runaway threads--it's probably fine.
 Use a timer and AJAX to have the Web page poll the server to see if
 the work is done.  (You could use Comet, but polling is probably  
 fine.
  Ignore this statement if you don't know what I'm talking  
 about.)  In
 the best case, you can use a progress bar on the page.  Just work  
 your
 way through it; I'm sure you'll be fine.

 Any recommendations on passing status between the worker thread  
 and the
 controller when it's polling?  I tried just using class variables,  
 but
 they don't seem to get updated between the threads...

 How were you updating the class variable?  ClassName.variable = foo?
  If you do self.variable = foo, you're shadowing the class variable.
  By the way, naturally, watch out for race conditions.  Another option
 is to use the queue module and have the worker thread push messages
 onto the queue, and the controller can read messages from the queue.
 I tend to prefer message queues over explicit lock management.

I've found this threadpool implementation useful for a similar task:

http://tinyurl.com/yw6xc9

Alberto


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Spawning a worker thread from the controller?

2007-05-04 Thread Matt Billenstein

Yeah, I was doing self.status = blah in the worker thread...  The
thread the controller is in doesn't seem to ever get this value...

Using Class.status = blah doesn't seem to help much either...

thx

m

On Fri, May 04, 2007 at 05:59:15PM -0700, Shannon -jj Behrens wrote:
 
 On 5/4/07, Matt Billenstein [EMAIL PROTECTED] wrote:
 
  On Fri, May 04, 2007 at 05:27:42PM -0700, Shannon -jj Behrens wrote:
   On 5/4/07, Matt [EMAIL PROTECTED] wrote:
Hi, I have a pylons app which I want to spawn a long-running process
from.  While this process is running (might be an hour or so), I want
the page that kicked off this process to just display status (maybe
referesh ever 30 seconds or so)...  Does anyone have some pointers on
how this should be done or what packages I should be looking into?
  
   I've done this before, but not in Pylons.  Spawning a long running
   process or thread is fine.  Watch out for Paste because I think Ian
   put in some code to watch for runaway threads--it's probably fine.
   Use a timer and AJAX to have the Web page poll the server to see if
   the work is done.  (You could use Comet, but polling is probably fine.
Ignore this statement if you don't know what I'm talking about.)  In
   the best case, you can use a progress bar on the page.  Just work your
   way through it; I'm sure you'll be fine.
 
  Any recommendations on passing status between the worker thread and the
  controller when it's polling?  I tried just using class variables, but
  they don't seem to get updated between the threads...
 
 How were you updating the class variable?  ClassName.variable = foo?
  If you do self.variable = foo, you're shadowing the class variable.
  By the way, naturally, watch out for race conditions.  Another option
 is to use the queue module and have the worker thread push messages
 onto the queue, and the controller can read messages from the queue.
 I tend to prefer message queues over explicit lock management.
 
 Best Regards,
 -jj
 
 -- 
 http://jjinux.blogspot.com/
 
  

-- 
Matt Billenstein
[EMAIL PROTECTED]
http://www.vazor.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: Spawning a worker thread from the controller?

2007-05-04 Thread Matt Billenstein

BTW, I'll add that I can do this in a simple standalone python script,
spawn a thread and have both that thread and the main thread stuff data
into a list or something...

thx

m

On Fri, May 04, 2007 at 06:17:29PM -0700, Matt Billenstein wrote:
 
 Yeah, I was doing self.status = blah in the worker thread...  The
 thread the controller is in doesn't seem to ever get this value...
 
 Using Class.status = blah doesn't seem to help much either...
 
 thx
 
 m
 
 On Fri, May 04, 2007 at 05:59:15PM -0700, Shannon -jj Behrens wrote:
  
  On 5/4/07, Matt Billenstein [EMAIL PROTECTED] wrote:
  
   On Fri, May 04, 2007 at 05:27:42PM -0700, Shannon -jj Behrens wrote:
On 5/4/07, Matt [EMAIL PROTECTED] wrote:
 Hi, I have a pylons app which I want to spawn a long-running process
 from.  While this process is running (might be an hour or so), I want
 the page that kicked off this process to just display status (maybe
 referesh ever 30 seconds or so)...  Does anyone have some pointers on
 how this should be done or what packages I should be looking into?
   
I've done this before, but not in Pylons.  Spawning a long running
process or thread is fine.  Watch out for Paste because I think Ian
put in some code to watch for runaway threads--it's probably fine.
Use a timer and AJAX to have the Web page poll the server to see if
the work is done.  (You could use Comet, but polling is probably fine.
 Ignore this statement if you don't know what I'm talking about.)  In
the best case, you can use a progress bar on the page.  Just work your
way through it; I'm sure you'll be fine.
  
   Any recommendations on passing status between the worker thread and the
   controller when it's polling?  I tried just using class variables, but
   they don't seem to get updated between the threads...
  
  How were you updating the class variable?  ClassName.variable = foo?
   If you do self.variable = foo, you're shadowing the class variable.
   By the way, naturally, watch out for race conditions.  Another option
  is to use the queue module and have the worker thread push messages
  onto the queue, and the controller can read messages from the queue.
  I tend to prefer message queues over explicit lock management.
  
  Best Regards,
  -jj
  
  -- 
  http://jjinux.blogspot.com/
  
   
 
 -- 
 Matt Billenstein
 [EMAIL PROTECTED]
 http://www.vazor.com/
 
  

-- 
Matt Billenstein
[EMAIL PROTECTED]
http://www.vazor.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---