+1 on Yaniv's post, looks quite interesting

On Thu, Aug 4, 2011 at 9:24 AM, Yaniv Aknin <[email protected]> wrote:

> While we are at the subject of interactive shells, I have a handy snippet
> that lets me drop into an interactive shell anytime:
>
> class RestoredStandardInputContext(object):
>     def __enter__(self):
>         self.backup_stdin = os.dup(sys.stdin.fileno())
>         os.dup2(sys.stdout.fileno(), sys.stdin.fileno())
>     def __exit__(self, error_type, error, traceback):
>         os.dup2(self.backup_stdin, sys.stdin.fileno())
>
> def interact(locals=None, plain=False):
>     with RestoredStandardInputContext():
>         code.interact(local=locals or
> inspect.currentframe().f_back.f_locals)
>
> __builtins__['INTERACT'] = interact
>
> This way, when I'm developing and I have uWSGI in the foreground and
> attached to a terminal, I can always add INTERACT() anywhere in my Python
> code (for example, inside a django view I'm debugging, or when I hit a
> special URL, or whatever) and get an interactive shell with the current
> local scope. Like I said, I found it very handy, maybe it should be added to
> uwsgi (from uwsgi import interact?) maybe not.
>
> To do something similar for a backgrounded process without a terminal, I
> also have a more complex snippet to fork the current process and launch
> manhole<http://twistedmatrix.com/documents/8.1.0/api/twisted.manhole.html>,
> twisted's in-process Python shell over telnet. I use this in production when
> I need to debug very weird cases, memory leaks, etc. I can paste this code
> here as well if someone is interested.
>
>  - Yaniv
>
>
> On Thu, Aug 4, 2011 at 8:07 AM, Roberto De Ioris <[email protected]> wrote:
>
>>
>> Hi everyone, i have just committed support for the uWSGI python
>> interactive shell. It is a simple/standard python shell living in the
>> uWSGI environment.
>>
>> For example:
>>
>> ./uwsgi --import sigme -s :3031 --pyshell -M --spooler myspool -p 4 -w
>> uwsgicc --cache 100
>>
>>
>> Will load 4 normal workers but the first will run a python shell from
>> which you cann call uwsgi api functions, monitor processes, issuing reload
>> and so on.
>>
>> I have found it very handy to test spooler jobs and caching.
>>
>> --
>> Roberto De Ioris
>> http://unbit.it
>> _______________________________________________
>> uWSGI mailing list
>> [email protected]
>> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>>
>
>
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>
>
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to