lordmauve / chopsticks

Chopsticks is an orchestration library: it lets you execute Python code on remote hosts over SSH.
https://chopsticks.readthedocs.io/
Apache License 2.0
157 stars 14 forks source link

Tunnel destructor prevents subsequent stderr interception #58

Open amigrave opened 6 years ago

amigrave commented 6 years ago

When the Tunnel.close() is called, the ioloop writer and reader instances are closed and oddly this makes subsequent stderr writes not intercepted by the orchestrator.

Eg:

# -*- coding: utf-8 -*-
import time

from chopsticks.tunnel import Local

def func():
    import __bubble__
    __bubble__.debug("Hi there!")
    time.sleep(1)  # Wait stderr to be flushed

for i in range(3):
    print("Call #%s" % i)
    m = Local()  # triggers __del__ in cpython starting 2nd iteration
    m.call(func)

outputs the following:

$ python3 test.py server
Call #0
[localhost] Hi there!
Call #1
Call #2

...no second output...

amigrave commented 6 years ago

Please note that the comment

 m = Local()  # triggers __del__ in cpython starting 2nd iteration

comes from a test I originally made outside of a loop. Anyway you get the idea.