Il giorno 04/ago/2011, alle ore 10:24, Yaniv Aknin ha scritto: > 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, > 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
Thanks, added to the Tips & Tricks page http://projects.unbit.it/uwsgi/wiki/TipsAndTricks > -- Roberto De Ioris http://unbit.it JID: [email protected] _______________________________________________ uWSGI mailing list [email protected] http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
