[Tutor] cython and threads, and feedparser

nathan tech nathan-tech at hotmail.com
Sun May 12 08:26:10 EDT 2019


Hello!

After a day of various attempts yesterday, I managed to get cython 
installed on my windows 10 machine.

Allow me to prefix this by saying, if there is somewhere else I should 
put this, II'M SORRY!


So I ran cython on my python project, and it worked fine, there was one 
error about an int, which I have put at the end of this document.

In summary though I don't think it has any relevance, might be me though.


Here's the problem.

In my program, when you load a new feed, the program launches a separate 
thread for using feedparser to download the rss feed, like this:

def loadfeed(feed):

  # do the feed loading code here

  # play a sound to say the feed was loaded


the loadfeed function is called through the threading module.

I put some print statements in, to establish what is going on in cython.

According to what I see, it launches the thread fine, it starts, and 
then it gets to this line:

     newfeed=feedparser.parse(url)

And just, stops.

I admit, it could be a speed problem, as I've not had the patients to 
let it run past about a minute, but in the normal, uncythonised python 
code, it runs in between 1 and 5 seconds, based on size of feed.

It doesn't error, it just acts like it has frozen.

The thread doesn't disappear, because the little status checker I have 
set up to keep an eye on threads within the program says it is still 
running, it just... seems not to.

I know this because, after the line above, I then have:

     print '2'

Which it never does.


I was wondering if there is a common cython... thing, I have missed 
here, where you have to compile feedparser separately? not at all? or 
something.

My worry is not speed, in this instance, 1 to 5 seconds is fine, all 
things considered and it being in a separate thread... I'm unworried at 
those timings.

My aim with cython was a simple, but nice enough, layer of protection

That being said, in my research I had read about the gil? Or something 
similar to do with only one python thread running at any one time in cython?

I admit to not understanding this, though.


Any explanations anyone can offer here would be greatly appreciated.

Thank you very much.

A confused Nate.


Compilation:

running build_ext
cythoning rss.py to rss.c
building 'rss' extension
C:\Users\natha\AppData\Local\Programs\Common\Microsoft\Visual C++ for 
Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG 
-Ic:\python2732\include -Ic:\python2732\PC /Tcrss.c 
/Fobuild\temp.win32-2.7\Release\rss.obj /openmp
rss.c
rss.c(6931) : warning C4047: '=' : 'int' differs in levels of 
indirection from 'PyObject *'
C:\Users\natha\AppData\Local\Programs\Common\Microsoft\Visual C++ for 
Python\9.0\VC\Bin\link.exe /DLL /nologo /INCREMENTAL:NO 
/LIBPATH:c:\python2732\libs /LIBPATH:c:\python2732\PCbuild 
/LIBPATH:c:\python2732\PC\VS9.0 /EXPORT:initrss 
build\temp.win32-2.7\Release\rss.obj "/OUT:C:\Users\natha\Dropbox\coding 
projects\python\luna rss\rss.pyd" 
/IMPLIB:build\temp.win32-2.7\Release\rss.lib 
/MANIFESTFILE:build\temp.win32-2.7\Release\rss.pyd.manifest
    Creating library build\temp.win32-2.7\Release\rss.lib and object 
build\temp.win32-2.7\Release\rss.exp
C:\Users\natha\AppData\Local\Programs\Common\Microsoft\Visual C++ for 
Python\9.0\WinSDK\Bin\mt.exe -nologo -manifest 
build\temp.win32-2.7\Release\rss.pyd.manifest 
"-outputresource:C:\Users\natha\Dropbox\coding projects\python\luna 
rss\rss.pyd;2"



More information about the Tutor mailing list