I was recently asked to pass some tests (pytest) in a Gitlab job for a professional project made in python 3.7.9 and Qt4, and it use some threads objects derivated from QThread Qt object to perform certain operations.
It works well on Windows and in a unix docker: when I call obj.start(), the thread start and do the obj.run() function, but for some reason the obj.start() function do nothing in the same unix docker in a job of a Gitlab pipeline, and so the obj.run() function is never executed, and return no errors...
I was wondering if someone know something similar about this problem and maybe to have some clue where to look to make a fix?
Because everything happens in a docker, it should behave the same on windows that in a Gitlab CI job, but all QThreads are not called - I think - because I have to call directly the obj.run() function if the environment variable os.environ['GITLAB_CI'] is defined to True, but my team and me agree that it is not good - for now - to adapt a program for a specific behaviour in a CI job... especially because is works well in the same docker on Windows...
EDIT: I have a class derivated from a QThread object: FTPDownloadThread(QtCore.QThread) (thread to download a file from a Server), and this class have (by inheritance) the .start() method that start the thread, which will download the desired file specified at object creation.
On Windows, Linux, in a Linux docker, etc., the following line work as expected, i.e. start the thread and download the file:
self._ftpThread = FTPDownloadThread(file, path, ...)
self._ftpThread.start()
but in a GitLab runner, I have to directly call the run() method manually :
self._ftpThread.start() if not os.environ.get('GITLAB_CI', False) else self._ftpThread.run()
(actually I have overwritted the start() function to call directly run() if in a GitLab CI Pipeline, but it's a temporary solution:)
def start(self):
"""
Convenience function that handle strange behaviour of threads in a GitLab pipelines for CICD jobs.
Will call either `FTPDownloadThread::super().start()` when not in a CICD pipeline, or directly `FTPDownloadThread::self.run()` in the other case.
"""
if not os.environ.get("GITLAB_CI", False):
# Not in a CI Pipeline
super().start()
else:
# In a CI Pipeline
self.run()
To be sure it was not a connection problem to the Server, I add a print after the download step and it appears in a GitLab CI only when I call directly the run() function, without any errors.
The same problem happens for all threads use, (writing a file, downloading or uploading a file, etc.).