×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Aug 2006
    Location
    SF Bay Area
    Posts
    27

    Embedded Interpreter and Importing Modules

    Calling urllib.urlopen() was crashing the embedded Python interpreter in my app, so I traced through urllib.py. It turns out that import re inside splittype() was causing the crash. The crash can be fixed by importing re in the same place urllib is imported. However there is no problem in the Emulator nor in in the Script Shell. Putting import re at the top of the module with the other import statments doesn't help either. My first thought is that it's a path issue*, but all the other modules import without a problem. I haven't yet traced re (really sre), but I don't really have time to dig further. I'm posting this hoping that somebody knows what is going on or, better yet, knows how to fix it generally.

    --
    V 21.0.016
    14-02-08
    RM-159
    Nokia N95 (01.01)
    PyS60 1.4.2 final

    * While looking at the path I noticed that the enclosing folder of the script run by RunScript() is added to sys.path with too many \'s. E.g. E:\\\\Python\\ as compared to c:\\resourse.
    Last edited by lakiolen; 2008-04-08 at 02:45. Reason: Device Info

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Embedded Interpreter and Importing Modules

    hi lakiolen
    is this problem with ur specific device only.
    the reason can with the faulty operation of python interpreter or u may have named a function in ur program with urllib.
    plz check out and give the feedback
    thanks

  3. #3
    Registered User
    Join Date
    Aug 2006
    Location
    SF Bay Area
    Posts
    27

    Re: Embedded Interpreter and Importing Modules

    This was pointed out by a user of my application. So there are at least 2 phones that exhibit the same problem, they are both N95s, but different revisions. Importing urllib is not the problem, it's urllib importing re that causes the crash. And it works when run from the Script Shell and Emulator, so the file is valid and the interpreter does work, in some contexts.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Embedded Interpreter and Importing Modules

    Quote Originally Posted by lakiolen View Post
    This was pointed out by a user of my application. So there are at least 2 phones that exhibit the same problem, they are both N95s, but different revisions. Importing urllib is not the problem, it's urllib importing re that causes the crash. And it works when run from the Script Shell and Emulator, so the file is valid and the interpreter does work, in some contexts.
    hi lakiolen
    if u dont mind can u show a bit of code of ur application. So that we can create a more clear picture.
    thanks

  5. #5
    Registered User
    Join Date
    Aug 2006
    Location
    SF Bay Area
    Posts
    27

    Re: Embedded Interpreter and Importing Modules

    There's a bit of setup in the beginning to create a dict and add it to the namespace, and also I copied some of default.py's code for setting up the sys.path variable the same way. HandleStdO is a static function for redirecting print statement and such to my app.

    Code:
    CSPyInterpreter* interpreter = CSPyInterpreter::NewInterpreterL();
    interpreter->iStdO = (HandleStdO);
    char* argv[1];
    int argc = 0;
    argv[0] = (char*)iFile.PtrZ();
    argc++;
    
    PyEval_RestoreThread(PYTHON_TLS->thread_state);
    
    PyObject *row = PyDict_New();
    TInt size = names->MdcaCount();
    for (int ii = 0; ii < size; ii++)
    	{
    	TPtrC ptr = names->MdcaPoint(ii);
    	PyObject *key = Py_BuildValue("u#", ptr.Ptr(), ptr.Length());
    	
    	ptr.Set(values->MdcaPoint(ii));
    	PyObject *value = Py_BuildValue("u#", ptr.Ptr(), ptr.Length());
    	PyDict_SetItem(row, key, value);
    	Py_DECREF(key);
    	Py_DECREF(value);
    	}
    PyObject *builtin = PyImport_ImportModule("__builtin__");
    PyObject *builtin_dict = PyModule_GetDict(builtin);
    Py_DECREF(builtin);
    
    PyDict_SetItemString(builtin_dict, "current_row", row);
    Py_DECREF(row);
    //PyRun_SimpleString("print current_row");
    
    PyRun_SimpleString("import sys, os");
    PyRun_SimpleString("for path in ('c:\\python\\lib','e:\\python\\lib'):\n  if os.path.exists(path):\n    sys.path.append(path)\n");
    //PyRun_SimpleString("print sys.path");
    
    PyEval_SaveThread();
    
    TInt err = interpreter->RunScript(argc, argv);
    if (err != KErrNone)
    	{
    	interpreter->PrintError();
    	}
    delete interpreter;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×