Jython: only one successful connection attempt using sockets

Asked by Damian on 2020-11-10

I'd be grateful if somebody help me to solve the following issue.

I am trying to connect with server (local on my machine) using sockets. I noticed that the connection works fine only once after first lunching of the SikuliX IDE. Each another attempt fails. I have familiarized with the similar query (674852) reported by matteoa 2 years ago but this solution would not be enough good in my case.

Mayby within this time somebody else met this problem?

Thanks for help in advance.

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:

This question was reopened

RaiMan (raimund-hocke) said : #1

please paste a code snippet

Damian (damdam30) said : #2

This is the fundamental code snippet which I use to connect as a client to the server:

import socket

class TCPControler:

    IP = ""
    PORT = 10002

    def __init__(self):
        self._TCPSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self._TCPSocket.connect((self.IP, self.PORT))
        except ValueError as error:
        except OSError as error:
            print("Unable to open TCP port %s:%s" % (self.IP.upper(), str(self.PORT)), error)

    def __del__(self):

def main():
    TcpCtrl = TCPControler()


Moreover, I noticed that destructor in jython works with delay or at all (I mean that it does not execute its code just after the Jython process stops working). In order to debug this issue I added the "print" functions in __init__ and __del__ member functions . It looks like the __del__ function in jython is invoked while garbage collector starts working (or similar tool).

Has someboody meet with such issue too?

RaiMan (raimund-hocke) said : #3

When running scripts in the SikuliX IDE, the Jython session is only terminated, if the IDE is terminated.

Hence each script runs in the same Jython context.

To get a new Jython context for every scriptrun, run your script from command line.

For testing purposes in the IDE, it might be worth to delete the TCPControler() instance at script end.

Can you help with this problem?

Provide an answer of your own, or ask Damian for more information if necessary.

To post a message you must log in.