Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

non PyQt module stops working after QApplication start

Tags:

python

qt

pyqt

In 2014 I have written a PyQt4 app that used a non PyQt module within and it worked as it should for nearly two years. Now, the non PyQt module had stopped working as expected within PyQt application (I have qt4 and qt5 ports, both share the problem). Below is a sample code to illustrate what is going on:

#! /usr/bin/env python3
import sys, getopt
from PyQt5.QtWidgets import QApplication # or PyQt4

# non PyQt module:
import mymodule

# demo of the mymodule use. It returns nested list
# with info about objects saved in fname

fname = "/my/file/name"
res0 = mymodule.getnames(fname)
# res0 = [[...],...,[...]] the way it should
#
app = QApplication(sys.argv)
...
# with or without actual run of the application via
# app.exec_()
...
res2 = mymodule.getnames(fname)
# this time the result is:
# res2 = None

Originally, I called the method of mymodule from within PyQt app and it returned the nested list, now it returns None. I have tried to find any explanation or clarification, why the observed behaviour has changed but failed to do so.

I have isolated the code responsible for rendering the mymodule behaviour to the call QApplication([sys.argv]) and wondered if anyone has an idea what is going on. What bugs me the most is, that the module is functional before the application start, but after that not any more.

Some further details about mymodule: it is a wrapper of a C library written in mymodule.c and installed via the python setup.py install call.

Thank you for any comments in advance!

[Edit] Further informations about mymodule:

mymodule.c code snippet

#include <Python.h>
#include <extlib.h>
#include <math.h>

...
static PyObject * mymodule_getnames(PyObject *self, PyObject *args)
{
char *filename;

if (!PyArg_ParseTuple(args, "s", &filename))
    return NULL;
FILE *fp = extlib_func(filename);
...
PyObject *names = PyList_New(0);
...  
PyList_Append(names, Py_BuildValue("s", title));
...
return names;
}

...

int main(int argc, char *argv[])
{
Py_SetProgramName(
#if PY_MAJOR_VERSION >= 3
                (wchar_t *)
#endif
                argv[0]);
Py_Initialize();
return 0;
}
like image 302
LynxLike Avatar asked Nov 16 '25 16:11

LynxLike


1 Answers

I have resolved the problem by not using anaconda as my python package manager. By installing everything in the system it worked as it should again. But the question still remains since the reason why is it not working within anaconda (but did for such a long time) is still beyond me.

I have posted this answer but will not accept it, if someone comes with an explanation of the phenomena. If after some time there will be no other reply I will mark it accepted to unclutter the questions pool.

Thank you all for your time and suggestions.

like image 131
LynxLike Avatar answered Nov 19 '25 07:11

LynxLike