Link to home
Start Free TrialLog in
Avatar of Errang Genevre
Errang Genevre

asked on

Best practices for multi-threading in Python

Hello,

I'm fairly new to Python; and I'm trying to find some resources that properly explains how to structure a multi-threaded Python project. This will be running in GNU/Linux.

My main concern is that I have a dictionary that needs to be read by all the threads; would it be possible to access the dictionary in each thread without explicitly passing the variable into each thread?

Also, I would need to write into multiple files; would it be better to have one thread that accesses these files, or is Python/Unix smart enough to allow one thread to finish writing the entire line before another thread jumps in to write something?

Appreciate any advice on this!
Avatar of aikimark
aikimark
Flag of United States of America image

@Errang Genevre

Can use use a global variable for the dictionary?
Avatar of Errang Genevre
Errang Genevre

ASKER

And import it into the multi threaded process?
SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!