gevent.backdoor – Interactive greenlet-based network console that can be used in any process

The BackdoorServer provides a REPL inside a running process. As long as the process is monkey-patched, the BackdoorServer can coexist with other elements of the process.

class BackdoorServer(listener, locals=None, banner=None, **server_args)

Bases: gevent.server.StreamServer

Provide a backdoor to a program for debugging purposes.

Warning

This backdoor provides no authentication and makes no attempt to limit what remote users can do. Anyone that can access the server can take any action that the running python process can. Thus, while you may bind to any interface, for security purposes it is recommended that you bind to one only accessible to the local machine, e.g., 127.0.0.1/localhost.

Basic usage:

from gevent.backdoor import BackdoorServer
server = BackdoorServer(('127.0.0.1', 5001),
                        banner="Hello from gevent backdoor!",
                        locals={'foo': "From defined scope!"})
server.serve_forever()

In a another terminal, connect with...:

$ telnet 127.0.0.1 5001
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Hello from gevent backdoor!
>> print(foo)
From defined scope!

Changed in version 1.2a1: Spawned greenlets are now tracked in a pool and killed when the server is stopped.

Parameters:
  • locals – If given, a dictionary of “builtin” values that will be available at the top-level.
  • banner – If geven, a string that will be printed to each connecting user.
handle(conn, _address)

Interact with one remote user.

Changed in version 1.1b2: Each connection gets its own locals dictionary. Previously they were shared in a potentially unsafe manner.

Next page: gevent.fileobject – Wrappers to make file-like objects cooperative