• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybuilder / pybuilder / 16613314016

30 Jul 2025 04:14AM UTC coverage: 84.008% (-0.1%) from 84.146%
16613314016

push

github

arcivanov
Release 0.13.16

2167 of 2671 branches covered (81.13%)

Branch coverage included in aggregate %.

5534 of 6496 relevant lines covered (85.19%)

36.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.4
/src/main/python/pybuilder/plugins/python/remote_tools/__init__.py
1
#   -*- coding: utf-8 -*-
2
#
3
#   This file is part of PyBuilder
4
#
5
#   Copyright 2011-2020 PyBuilder Team
6
#
7
#   Licensed under the Apache License, Version 2.0 (the "License");
8
#   you may not use this file except in compliance with the License.
9
#   You may obtain a copy of the License at
10
#
11
#       http://www.apache.org/licenses/LICENSE-2.0
12
#
13
#   Unless required by applicable law or agreed to in writing, software
14
#   distributed under the License is distributed on an "AS IS" BASIS,
15
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
#   See the License for the specific language governing permissions and
17
#   limitations under the License.
18

19
from pybuilder.remote import Process, PipeShutdownError, RemoteObjectPipe, logger, log_to_stderr
44✔
20

21
__all__ = ["RemoteObjectPipe", "start_tool", "Tool", "PipeShutdownError", "logger"]
44✔
22

23

24
class Tool:
44✔
25
    def start(self, pipe):
44✔
26
        """Starts the tool in the tool process"""
27
        pass
×
28

29
    def stop(self, pipe):
44✔
30
        """Stops the tool in the tool process"""
31
        pass
×
32

33

34
def start_tool(pyenv, tools, group=None, name=None, logging=None, tracing=None):
44✔
35
    """
36
    Starts a tool process
37
    """
38

39
    if logging:
44✔
40
        log_to_stderr()
44✔
41
        logger.setLevel(int(logging))
44✔
42

43
    pipe = RemoteObjectPipe.new_pipe()
44✔
44
    proc = Process(pyenv, group=group, name=name,
44✔
45
                   target=_traced_tool if tracing else _instrumented_tool, args=(tools, pipe))
46

47
    try:
44✔
48
        proc.start()
44✔
49
    finally:
50
        pipe.close_client_side()
44✔
51

52
    pipe.receive()  # Pickle protocol selection
44✔
53
    return proc, pipe
44✔
54

55

56
def _traced_tool(tools, pipe):
44✔
57
    import trace
×
58

59
    def _print(*objects, sep=' ', end='', **kwargs):
×
60
        logger.debug((sep.join(objects) + end).rstrip("\r\n"))
×
61

62
    trace.print = _print
×
63
    trace.Trace(count=0).runfunc(_instrumented_tool, tools, pipe)
×
64

65

66
def _instrumented_tool(tools, pipe):
44✔
67
    try:
×
68
        for tool in tools:
×
69
            tool.start(pipe)
×
70

71
        while True:
72
            pipe.receive()
×
73

74
    except PipeShutdownError:
×
75
        for tool in reversed(tools):
×
76
            tool.stop(pipe)
×
77
    except (SystemExit, KeyboardInterrupt):
×
78
        raise
×
79
    except Exception as e:
×
80
        pipe.close(e)
×
81
    finally:
82
        try:
×
83
            pipe.close()
×
84
        finally:
85
            import threading
×
86

87
            main = threading.main_thread()
×
88
            current = threading.current_thread()
×
89

90
            if main != current:
×
91
                logger.warn("current thread %s is not the main %s in the tool process", current, main)
×
92

93
            blocked_threads = False
×
94
            for t in threading.enumerate():
×
95
                if not t.daemon and t != current:
×
96
                    logger.warn("non-daemon thread %s is blocking the tool process shutdown", t)
×
97
                    blocked_threads = True
×
98

99
            if blocked_threads:
×
100
                import os
×
101
                import atexit
×
102

103
                try:
×
104
                    atexit._run_exitfuncs()
×
105
                finally:
106
                    os._exit(1)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc