Esempio n. 1
0
 def test_copy_path(self):
     stream = QueueStream()
     qstream = {'stream': stream}
     old_environ = os.environ
     old_paths = sys.path[:]
     try:
         sys.path = ['XYZ']
         os.environ = {'COCONUTS': 'MIGRATE'}
         cmd = ('%s -c "import sys; '
                'sys.stdout.write(\':\'.join(sys.path)); '
                ' sys.stdout.flush()"') % sys.executable
         watcher = Watcher('xx',
                           cmd,
                           copy_env=True,
                           copy_path=True,
                           stdout_stream=qstream)
         watcher.start()
         time.sleep(3.)
         watcher.stop()
         data = [v for k, v in stream.get().items()][1]
         data = ''.join(data)
         self.assertTrue('XYZ' in data, data)
     finally:
         os.environ = old_environ
         sys.path[:] = old_paths
Esempio n. 2
0
class SomeWatcher(threading.Thread):

    def __init__(self):
        threading.Thread.__init__(self)
        self.stream = QueueStream()
        self.loop = self.watcher = None

    def run(self):
        qstream = {'stream': self.stream}
        old_environ = os.environ
        old_paths = sys.path[:]
        try:
            sys.path = ['XYZ']
            os.environ = {'COCONUTS': 'MIGRATE'}
            cmd = ('%s -c "import sys; '
                   'sys.stdout.write(\':\'.join(sys.path)); '
                   ' sys.stdout.flush()"') % sys.executable

            self.loop = ioloop.IOLoop.instance()
            self.watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
                                   stdout_stream=qstream, loop=self.loop)
            self.watcher.start()
            self.loop.start()
        finally:
            os.environ = old_environ
            sys.path[:] = old_paths

    def stop(self):
        if self.loop is not None:
            self.loop.stop()
        if self.watcher is not None:
            self.watcher.stop()
        self.join()
Esempio n. 3
0
class SomeWatcher(threading.Thread):

    def __init__(self, **kw):
        threading.Thread.__init__(self)
        self.stream = QueueStream()
        self.loop = self.watcher = None
        self.kw = kw

    def run(self):
        qstream = {'stream': self.stream}
        old_environ = os.environ
        old_paths = sys.path[:]
        try:
            sys.path = ['XYZ']
            os.environ = {'COCONUTS': 'MIGRATE'}
            cmd = ('%s -c "import sys; '
                   'sys.stdout.write(\':\'.join(sys.path)); '
                   ' sys.stdout.flush()"') % sys.executable

            self.loop = ioloop.IOLoop()
            self.watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
                                   stdout_stream=qstream, loop=self.loop,
                                   **self.kw)
            self.watcher.start()
            self.loop.start()
        finally:
            os.environ = old_environ
            sys.path[:] = old_paths

    def stop(self):
        if self.loop is not None:
            self.loop.stop()
        if self.watcher is not None:
            self.watcher.stop()
        self.join()
Esempio n. 4
0
class SomeWatcher(threading.Thread):
    def __init__(self, **kw):
        threading.Thread.__init__(self)
        self.stream = QueueStream()
        self.loop = self.watcher = None
        self.kw = kw

    def run(self):
        qstream = {"stream": self.stream}
        old_environ = os.environ
        old_paths = sys.path[:]
        try:
            sys.path = ["XYZ"]
            os.environ = {"COCONUTS": "MIGRATE"}
            cmd = (
                '%s -c "import sys; ' "sys.stdout.write(':'.join(sys.path)); " ' sys.stdout.flush()"'
            ) % sys.executable

            self.loop = ioloop.IOLoop()
            self.watcher = Watcher(
                "xx", cmd, copy_env=True, copy_path=True, stdout_stream=qstream, loop=self.loop, **self.kw
            )
            self.watcher.start()
            self.loop.start()
        finally:
            os.environ = old_environ
            sys.path[:] = old_paths

    def stop(self):
        if self.loop is not None:
            self.loop.stop()
        if self.watcher is not None:
            self.watcher.stop()
        self.join()
Esempio n. 5
0
class SomeWatcher(object):

    def __init__(self, loop=None, **kw):
        self.stream = QueueStream()
        self.watcher = None
        self.kw = kw
        if loop is None:
            self.loop = tornado.ioloop.IOLoop.instance()
        else:
            self.loop = loop

    @tornado.gen.coroutine
    def run(self):
        qstream = {'stream': self.stream}
        old_environ = os.environ
        old_paths = sys.path[:]
        try:
            sys.path = ['XYZ']
            os.environ = {'COCONUTS': 'MIGRATE'}
            cmd = ('%s -c "import sys; '
                   'sys.stdout.write(\':\'.join(sys.path)); '
                   ' sys.stdout.flush()"') % sys.executable

            self.watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
                                   stdout_stream=qstream, loop=self.loop,
                                   **self.kw)
            yield self.watcher.start()
        finally:
            os.environ = old_environ
            sys.path[:] = old_paths

    @tornado.gen.coroutine
    def stop(self):
        if self.watcher is not None:
            yield self.watcher.stop()
Esempio n. 6
0
class SomeWatcher(object):

    def __init__(self, loop=None, **kw):
        self.stream = QueueStream()
        self.watcher = None
        self.kw = kw
        if loop is None:
            self.loop = tornado.ioloop.IOLoop.instance()
        else:
            self.loop = loop

    @tornado.gen.coroutine
    def run(self):
        qstream = {'stream': self.stream}
        old_environ = os.environ
        old_paths = sys.path[:]
        try:
            sys.path = ['XYZ']
            os.environ = {'COCONUTS': 'MIGRATE'}
            cmd = ('%s -c "import sys; '
                   'sys.stdout.write(\':\'.join(sys.path)); '
                   ' sys.stdout.flush()"') % sys.executable

            self.watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
                                   stdout_stream=qstream, loop=self.loop,
                                   **self.kw)
            yield self.watcher.start()
        finally:
            os.environ = old_environ
            sys.path[:] = old_paths

    @tornado.gen.coroutine
    def stop(self):
        if self.watcher is not None:
            yield self.watcher.stop()
Esempio n. 7
0
 def test_copy_path(self):
     stream = QueueStream()
     qstream = {'stream': stream}
     old_environ = os.environ
     old_paths = sys.path[:]
     try:
         sys.path = ['XYZ']
         os.environ = {'COCONUTS': 'MIGRATE'}
         cmd = ('%s -c "import sys; '
                'sys.stdout.write(\':\'.join(sys.path)); '
                ' sys.stdout.flush()"') % sys.executable
         watcher = Watcher('xx', cmd, copy_env=True, copy_path=True,
                           stdout_stream=qstream)
         watcher.start()
         time.sleep(3.)
         watcher.stop()
         data = [v for k, v in stream.get().items()][1]
         data = ''.join(data)
         self.assertTrue('XYZ' in data, data)
     finally:
         os.environ = old_environ
         sys.path[:] = old_paths