[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

>Write program in python >Decide to make it threaded. >few

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 25
Thread images: 1

File: python.png (80KB, 1000x1000px)
python.png
80KB, 1000x1000px
>Write program in python
>Decide to make it threaded.
>few hours later.
>It dosen't run faster than before.
>Google
>Because of the Global interpreter lock (GIL) python is in reality single threaded no matter how much you use the threading module.

Is this the year 2000? holy shit python get your shit together.
>>
You need to enable hardware acceleration for that.
>>
The Global Interpreter Lock is pretty much here to stay. If you really need to, use processes.
>>
>>55936222
>be OP
>be tech illiterate enough to be stumped by this for hours
>not just using processes
>>
Use Perl, it doesn't have a GIL. Shit, even PHP has proper multi-threading these days.
>>
>>55936222
Even if you can run a program multithreaded it doesn't necessarily improve performance. usually unless there is a good reason to go multithreaded or parallel, doing those will decrease performance.

That said, you can disable the GI lock by using a C/C++ library. It's very straightforward to do. Or you can do process level parallization.
>>
>>55936222
Threads are not made to make cpu intensive tasks faster on multicore dumass. Theyre made to access disk while sending data to socket, compute stuff while rendering gui and so on. Use processes along with sockets/queues/pipes to make things multicpu-intensive
>>
Are you sure your program is even CPU-bound? Unless you are doing numerical shit, it probably isn't.
>>
Thanks to the GIL you don't have to give a single flying fuck to inter thread communication, variable access locks and shit like that.

You can spawn 1000 threads where they all use and abuse the same object without giving it a single thought about what could go wrong.
>>
>python
>>
>>55936222
Made the same misstake once. Go Google multiprocessing to sidestep the lock.
>>
>>55937053
Yeah but it's slow. Clojure achieves the same end result with its STM and is faster.
>>
>>55936222
http://cython.org/

I used this in my bachelor thesis when trying to find out how good idea is to use Python VS Java VS C++ in O(n**5) algorithms in neuro-imagining software.

Cython offers with no hard thinking +40% speed boost (depends on how good your C compiler is). Still it was utter shit, because the same task (only heavy math done in "static" memory):
>Python 6 hours
>Java 1 hour
>C++ 30 seconds.

Cython can maybe solve your problem mate with bullshit tier interpret. Maybe some day Python will learn "just in time" and will be as slow as java.
>>
>>55936222
https://www.youtube.com/watch?v=LMxuDrVs0HE
>>
>>55936222
If you're on a unix-y OS and not some shitty ancient OS, you're better off using processes because they're almost as lightweight as threads. It's the unix way
>>
>>55936222
Your fault for using a meme language
>>
>>55938688
Holy shit those numbers. And people doing Java actually ironically claims it's faster than C++.
>>
Just use processes.
>>
>>55936620
>Threads are not made to make cpu intensive tasks faster on multicore dumass. Theyre made to access disk while sending data to socket, compute stuff while rendering gui and so on. Use processes along with sockets/queues/pipes to make things multicpu-intensive
I think you're on the mount stupid about your knowledge of threads.
Threads allow multiple processes to work in the same context (the same data) versus processes that have different contexts, so while your example can be valid uses for threads, you also use threads to make cpu intesive tasks faster on multicore/multithreads processors.
Tasks like compression/decompression (files, pictures, videos), treating large volume of data (XML/HTML parsing), sorting data etc...
>>
>>55938688
Pypy is JIT's python, but it still uses CPython's runtime so it's rarely any faster. The only way Python JIT will become faster is if the entire runtime is re-written in Python. Which is easily 1 million man hours. It will never happen. Python will fade into disuse sometime early 2020's.
>>
>>55938688
>>55938855
Depending on cases, java CAN be faster/just as fast as C/C++ because JIT allows you do optimise in ways that static compilation can't but there are caveats :
- initial execution (before optimisation and JIT kicks in) is always slower, usually more than 10x
- it uses a LOT more RAM
- JVM startup is sloooooooooow
- some things are just slow no matter what (like files, network or system calls)
>>
>>55939049
No. Java is never better, for any purpose. Leave.
>>
>>55936222
thats what you get for wasting your time learning shitty languages anon

we all know Shockwave is the future
>>
>>55939049
The point is, each language is good for something.

Python is good for people who never done any programs, but needs to do something fast. Java will never die because EE and everything around it.

Also doing something in C++ takes a lot of skill and time. When you want to build something huge, it is much easier to get 20 average Java developers then 20 C++ developers.

Or anything web related. Writing any kind of CMS in C would be suicide in the long run. Besides the best paid jobs are currently in Java .-)
>>
>>55936222
Threads in python actually makes it slower. Just use processes.
Thread posts: 25
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.