Home Download Buy Blog Forum Support

How Python threading is internally organized by SublimeText?

How Python threading is internally organized by SublimeText?

Postby itzhak on Sun Oct 28, 2012 9:33 am

Hi Guys!

I came across couple of plugin tutorials and I feel confused about correct use of Python threads in SublimeText plugin development.

It is the common issue with Python GIL which doesn't allow two threads to do calculations at the same time (at least with CPython interpreter, which I guess is used inside Sublime?..). E.g. you can have N threads making IO (say, downloading pages) at a time, but only one thread actually doing some CPU extensive work, like parsing the page's content.

So, what is the sense in running CPU extensive operations in separate thread in plugin (like walking through project directories and examining files for further autocompletion) if it still will make the whole interpreter wait for it?

How is it internally organized in SublimeText and how thus to use threads correctly?

Thank you in advance,
Ilya.
itzhak
 
Posts: 1
Joined: Sun Oct 28, 2012 9:24 am

Re: How Python threading is internally organized by SublimeText?

Postby quarnster on Sun Oct 28, 2012 11:27 am

itzhak wrote:So, what is the sense in running CPU extensive operations in separate thread in plugin (like walking through project directories and examining files for further autocompletion) if it still will make the whole interpreter wait for it?


It's true that the GIL only allows one thread to run the interpreter at any time, however there's still scheduling going on so one thread's work is interrupted and the interpreter starts interpreting another on a regular basis. Say your task takes 10 seconds to complete this means that if you do it in the main thread, the mainthread will be blocked for 10 seconds and if you do it in a separate thread, the interpreter will switch between the two threads many, many times per second ensuring that both threads get work done.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am


Return to Plugin Development

Who is online

Users browsing this forum: Alexa [Bot] and 4 guests