PyEval_InitThreads in Python 3: How/when to call it? (the saga continues ad nauseam)

Your understanding is correct: invoking PyEval_InitThreads does, among other things, acquire the GIL. In a correctly written Python/C application, this is not an issue because the GIL will be unlocked in time, either automatically or manually. If the main thread goes on to run Python code, there is nothing special to do, because Python interpreter … Read more

Custom transformer for sklearn Pipeline that alters both X and y

Modifying the sample axis, e.g. removing samples, does not (yet?) comply with the scikit-learn transformer API. So if you need to do this, you should do it outside any calls to scikit learn, as preprocessing. As it is now, the transformer API is used to transform the features of a given sample into something new. … Read more

How to read line by line in pdf file using PyPdf?

Looks like what you have is a large chunk of text data that you want to interpret line-by-line. You can use the StringIO class to wrap that content as a seekable file-like object: >>> import StringIO >>> content=”big\nugly\ncontents\nof\nmultiple\npdf files” >>> buf = StringIO.StringIO(content) >>> buf.readline() ‘big\n’ >>> buf.readline() ‘ugly\n’ >>> buf.readline() ‘contents\n’ >>> buf.readline() ‘of\n’ … Read more

Can a Python Fabric task invoke other tasks and respect their hosts lists?

Since Fabric 1.3, the execute helper is now available to do just this. The documentation is available here: Intelligently executing tasks with execute. Here is the example they use: from fabric.api import run, roles, execute env.roledefs = { ‘db’: [‘db1’, ‘db2’], ‘web’: [‘web1’, ‘web2’, ‘web3’], } @roles(‘db’) def migrate(): # Database stuff here. pass @roles(‘web’) … Read more

error code: 521