Search code examples
pythoneventlet

Can I call functions or change variables throught eventlet.backdoor in Python?


I wrote this minimal code to explain my case:

import threading
import time
import eventlet
from eventlet import backdoor

eventlet.monkey_patch()

global should_printing
should_printing = True

def turn_off_printing():
    global should_printing
    should_printing = not should_printing

def printing_function():
    global should_printing
    while should_printing == True:
        print "printing"
        time.sleep(1)

def console():
    while True:
        print "inside console"
        time.sleep(1)

if __name__ == '__main__':
    eventlet.spawn(backdoor.backdoor_server, eventlet.listen(('localhost', 3000)))

    thread = threading.Thread(target=printing_function)
    thread.start()

    thread = threading.Thread(target=console)
    thread.start()

After executing it, I connect through telnet, import my module and call turn_off_printing(). But it not works. Do i made mistake, or it is not possible?


Solution

  • As fthinker said in comment above:

    It doesn't look like the backdoor server is using the same namespace. Typing the function names said they were undefined and your variable 'should_printing' is undefined as well. I tested this while telnetted into the interpreter set up by the backdoor server.

    (if fthinker reply as answer post i will delete this post)