<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def listen(self, port=None):
 """Make the fake executable listen to the specified port. Possible values for 'port' are: - None: Allocate immediately a free port and instruct the fake executable to use it when it's invoked. This is subject to a race condition, if that port that was free when listen() was invoked later becomes used before the fake executable had chance to bind to it. However it has the advantage of exposing the free port as FakeExecutable.port instance variable, that can easily be consumed by tests. - An integer: Listen to this specific port. """

        if port is None:
            port = allocate_port()
        self.port = port
        self.line("import socket")
        self.line("sock = socket.socket()")
        self.line("sock.bind(('localhost', {}))".format(self.port))
        self.log("listening: %d" % self.port)
        self.line("sock.listen(0)")