Distinguish between pserve and pshell in main

17 views
Skip to first unread message

Martin Stein

unread,
Jul 29, 2015, 8:06:29 AM7/29/15
to pylons-discuss
Hi all,

is there an elegant way in the central main(..)-function to determine if the application was started from pserve or pshell? I'm launching a background thread from there, which does some regular polling of a 3rd-party API. Obviously I don't want to start that thread when the application is launched from pshell, but I don't see an easy way to prevent that.

Thanks and best regards,
Martin

Oliver

unread,
Jul 29, 2015, 8:33:50 AM7/29/15
to pylons-...@googlegroups.com
You could check which modules are imported... the pserve script is loading stuff from paste.deploy so these modules
should be present in sys.modules
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> pylons-discus...@googlegroups.com <mailto:pylons-discus...@googlegroups.com>.
> To post to this group, send email to pylons-...@googlegroups.com <mailto:pylons-...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

Gael Pasgrimaud

unread,
Jul 29, 2015, 8:39:38 AM7/29/15
to pylons-discuss, mstei...@gmail.com


On Wednesday, July 29, 2015 at 2:06:29 PM UTC+2, Martin Stein wrote:
Hi all,

is there an elegant way in the central main(..)-function to determine if the application was started from pserve or pshell?

Don't know if it's elegant but sys.argv[0].endswith('pshell') is true when you are using pshell

Martin Stein

unread,
Jul 29, 2015, 9:13:39 AM7/29/15
to pylons-discuss, ga...@gawel.org
I like the sys.argv[0]-approach: It's simple and readable. Should have thought of it myself.
And longer term I should probably switch to an approach with a separate daemonized process (using Pyramid's command-line helpers).

Thanks both of you.
Reply all
Reply to author
Forward
0 new messages