Threads, GIL and re.match() performance

M

Mirko Dziadzka

Hi all

I understand that the C implementation of Python use a global interpreter
lock to avoid problems, so doing CPU bound tasks in multiple threads
will not result in better performance on multi-CPU systems.

However, I assumed that calls to (thread safe) C Library functions
release the global interpreter lock.

Today I checked the performance of some slow re.match() calls and found,
that the do not run in parallel on a multi-CPU system.

1) Is there a reason for this?
2) Is the regex library not thread-safe?
3) Is it possible, to release the GIL in re.match() to
get more performance?

I'm using Python 2.5

Thanks for your help

Mirko
 
A

Aahz

I understand that the C implementation of Python use a global interpreter
lock to avoid problems, so doing CPU bound tasks in multiple threads
will not result in better performance on multi-CPU systems.

However, I assumed that calls to (thread safe) C Library functions
release the global interpreter lock.

Generally speaking that only applies to I/O calls.
Today I checked the performance of some slow re.match() calls and found,
that the do not run in parallel on a multi-CPU system.

1) Is there a reason for this?
2) Is the regex library not thread-safe?
3) Is it possible, to release the GIL in re.match() to
get more performance?

Theoretically possible, but the usual rule applies: patches welcome
 
J

Jeff

However, I assumed that calls to (thread safe) C Library functions
release the global interpreter lock.

This is mainly applicable to external C libraries. The interface to
them may not be thread-safe; anything that uses the Python API to
create/manage Python objects will require use of the GIL. So the
actual regex search may release the GIL, but the storing of results
(and possibly intermediate results) would not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top