How to use the watchgod.run_process function in watchgod

To help you get started, we’ve selected a few watchgod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samuelcolvin / watchgod / tests / test_run_process.py View on Github external
def test_dead_callback(mocker):
    mock_start_process = mocker.patch('watchgod.main._start_process')
    mock_start_process.return_value = FakeProcess(is_alive=False)
    mock_kill = mocker.patch('watchgod.main.os.kill')
    c = mocker.MagicMock()

    assert run_process('/x/y/z', object(), watcher_cls=FakeWatcher, callback=c, debounce=5, min_sleep=1) == 1
    assert mock_start_process.call_count == 2
    assert mock_kill.call_count == 0
    assert c.call_count == 1
    c.assert_called_with({'x'})
github samuelcolvin / watchgod / tests / test_run_process.py View on Github external
def test_alive_terminates(mocker):
    mock_start_process = mocker.patch('watchgod.main._start_process')
    mock_start_process.return_value = FakeProcess()
    mock_kill = mocker.patch('watchgod.main.os.kill')

    assert run_process('/x/y/z', object(), watcher_cls=FakeWatcher, debounce=5, min_sleep=1) == 1
    assert mock_start_process.call_count == 2
    assert mock_kill.call_count == 1
github samuelcolvin / watchgod / tests / test_run_process.py View on Github external
def test_alive_doesnt_terminate(mocker):
    mock_start_process = mocker.patch('watchgod.main._start_process')
    mock_start_process.return_value = FakeProcess(exitcode=None)
    mock_kill = mocker.patch('watchgod.main.os.kill')

    assert run_process('/x/y/z', object(), watcher_cls=FakeWatcher, debounce=5, min_sleep=1) == 1
    assert mock_start_process.call_count == 2
    assert mock_kill.call_count == 2
github samuelcolvin / watchgod / watchgod / cli.py View on Github external
if not path.is_dir():
        print('path "{}" is not a directory'.format(path), file=sys.stderr)
        return sys.exit(1)
    path = path.resolve()

    try:
        tty_path = os.ttyname(sys.stdin.fileno())
    except OSError:
        # fileno() always fails with pytest
        tty_path = '/dev/tty'
    except AttributeError:
        # on windows. No idea of a better solution
        tty_path = None
    logger.info('watching "%s/" and reloading "%s" on changes...', path, arg_namespace.function)
    set_start_method('spawn')
    run_process(path, run_function, args=(arg_namespace.function, tty_path), callback=callback)