GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( 19fcc2...697e45 )
by P.R.
03:59
created

EventQueueEmptyEventHandler.handle()   F

Complexity

Conditions 14

Size

Total Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
c 1
b 0
f 0
dl 0
loc 67
rs 2.6141

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like EventQueueEmptyEventHandler.handle() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
"""
2
Enarksh
3
4
Copyright 2013-2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
import fcntl
9
import os
10
import select
11
import signal
12
13
import zmq
14
15
from enarksh.event.Event import Event
16
from enarksh.message.Message import Message
0 ignored issues
show
Bug introduced by
The name message does not seem to exist in module enarksh.
Loading history...
Configuration introduced by
The import enarksh.message.Message could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
17
18
19
class EventQueueEmptyEventHandler:
20
    """
21
    An event handler for an empty event queue.
22
    """
23
    _wake_up_pipe = None
24
    """
25
    The wakeup file descriptor when a signal is received.
26
27
    :type: None|(int,int)
28
    """
29
30
    # ------------------------------------------------------------------------------------------------------------------
31
    @classmethod
32
    def init(cls):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
33
        cls._wake_up_pipe = os.pipe()
34
        fcntl.fcntl(cls._wake_up_pipe[0], fcntl.F_SETFL, os.O_NONBLOCK)
35
36
        signal.set_wakeup_fd(EventQueueEmptyEventHandler._wake_up_pipe[1])
37
38
    # ------------------------------------------------------------------------------------------------------------------
39
    @staticmethod
40
    def handle(_event, _event_data, spawner):
41
        """
42
        Handles an empty event queue event.
43
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
44
        :param  _event: The event.
45
        :param * _event_data: Not used.
46
        :param enarksh.spawner.Spawner.Spawner spawner: The spawner.
47
        """
48
        del _event, _event_data
49
50
        # List with all file descriptors for reading.
51
        # Add the file descriptor for waking up select when a signal has been received.
52
        read = [EventQueueEmptyEventHandler._wake_up_pipe[0]]
53
54
        # Add the sockets for incoming messages to the list of read file descriptors.
55
        zmq_fds = set()
56
        for socket in Message.message_controller.end_points.values():
57
            if socket.type in [zmq.PULL, zmq.REP]:
2 ignored issues
show
Bug introduced by
The Module zmq does not seem to have a member named PULL.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Module zmq does not seem to have a member named REP.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
58
                zmq_fd = socket.get(zmq.FD)
1 ignored issue
show
Bug introduced by
The Module zmq does not seem to have a member named FD.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
59
                read.append(zmq_fd)
60
                zmq_fds.add(zmq_fd)
61
62
        # Add the job handlers to the list of read file descriptors.
63
        for pid, job_handler in spawner.job_handlers.items():
0 ignored issues
show
Unused Code introduced by
The variable pid seems to be unused.
Loading history...
64
            fd_stdout = job_handler.stdout
65
            if fd_stdout >= 0:
66
                read.append(fd_stdout)
67
            fd_stderr = job_handler.stderr
68
            if fd_stderr >= 0:
69
                read.append(fd_stderr)
70
71
        # Unblock interrupts.
72
        signal.pthread_sigmask(signal.SIG_UNBLOCK, {signal.SIGCHLD, signal.SIGHUP})
73
74
        try:
75
            # Wait for a fd becomes available for read or wait for an interrupt.
76
            read, _, _ = select.select(read, [], [])
77
78
        except InterruptedError:
79
            # Ignore Interrupted system call errors (EINTR) in the select call.
80
            # Note: In Python 3.5 EINTR will not occur any more. Nevertheless, we must only allow interrupts here to
81
            # prevent unwanted side effect of the signal handlers.
82
            read = []
83
84
        # Block all interrupts to prevent interrupted system call errors (EINTR).
85
        signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGCHLD, signal.SIGHUP})
86
87
        zmq_event = False
88
        for fd in read:
89
            if fd in zmq_fds:
90
                # fd of the message queue is ready to receive data.
91
                zmq_event = True
92
            elif fd == EventQueueEmptyEventHandler._wake_up_pipe[0]:
93
                os.read(EventQueueEmptyEventHandler._wake_up_pipe[0], 512)
94
            else:
95
                # fd of one or more job handlers are ready to receive data.
96
                for job_handler in spawner.job_handlers.values():
97
                    if fd == job_handler.stdout:
98
                        job_handler.read(fd)
99
                    if fd == job_handler.stderr:
100
                        job_handler.read(fd)
101
102
        if zmq_event:
103
            spawner.zmq_incoming_message_event.fire()
104
        else:
105
            Event.event_controller.event_queue_empty.fire()  # XXX test queue is empty
106
107
# ----------------------------------------------------------------------------------------------------------------------
108