473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unique thread ID

Is there a way to obtain a unique ID for the current thread? I have an
object that I need to store local thread data in, and I don't want to
use threading.local because each thread might have multiple instances
of my object.
Jan 18 '08 #1
4 4002
Benjamin schrieb:
Is there a way to obtain a unique ID for the current thread? I have an
object that I need to store local thread data in, and I don't want to
use threading.local because each thread might have multiple instances
of my object.
You can use the thread itself, it's usable as key (that's what
threadlocals use for their implementation anyway)

But I don't understand your problem - all thread-local implementations I
know of (is there a standard?) can be instantiated in each object and
then offer a get/set method (keyed or not) - but without interfering
with outher instances of themselves of course.
Diez
Jan 18 '08 #2
Benjamin wrote:
Is there a way to obtain a unique ID for the current thread? I have an
object that I need to store local thread data in, and I don't want to
use threading.local because each thread might have multiple instances
of my object.
threading.get_ident() but please use threading.local. Nobody is going to
stop you if you use a list or dict in threading.local.

Christian

Jan 18 '08 #3
On Jan 18, 2:31 am, Christian Heimes <li...@cheimes.dewrote:
Benjamin wrote:
Is there a way to obtain a unique ID for the current thread? I have an
object that I need to store local thread data in, and I don't want to
use threading.local because each thread might have multiple instances
of my object.

threading.get_ident() but please use threading.local. Nobody is going to
stop you if you use a list or dict in threading.local.
then, I have to figure out how to represent an instance of my object
in threading.local. (The data also won't be garbage collect when my
object is, will it?) I think the unique id is elegant in this case.
>
Christian
Jan 19 '08 #4
En Fri, 18 Jan 2008 22:41:47 -0300, Benjamin <mu**************@gmail.com>
escribió:
On Jan 18, 2:31 am, Christian Heimes <li...@cheimes.dewrote:
>Benjamin wrote:
Is there a way to obtain a unique ID for the current thread? I have an
object that I need to store local thread data in, and I don't want to
use threading.local because each thread might have multiple instances
of my object.

threading.get_ident() but please use threading.local. Nobody is going to
stop you if you use a list or dict in threading.local.
then, I have to figure out how to represent an instance of my object
in threading.local. (The data also won't be garbage collect when my
object is, will it?) I think the unique id is elegant in this case.
I think you didn't get how threading.local works yet. It's a lot easier
than you imply. Just store your instances as attributes of a
threading.local object. You may use a list or dictionary if you want
multiple instances.
Read _threading_local.py, it contains a lot of examples.

--
Gabriel Genellina

Jan 19 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Claudio Jolowicz | last post by:
Is it possible to store unique objects in an STL container? Suppose an object of class C is unique: class C { public: C() {} ~C() {} private:
3
by: Jozef | last post by:
Hello, Is there any way to acquire a unique Machine ID, Hard Drive ID or Windows Installation ID? Im looking for a way to uniquely identify a physical installation and connection. The problem...
8
by: Abhishek | last post by:
Hi! I need to create a unique password everytime i click a button . what technique/Algo should i follow. Abhishek
10
by: Jerry LeVan | last post by:
Hi, I am futzing around with Andrew Stuarts "Catchmail" program that stores emails into a postgresql database. I want to avoid inserting the same email more than once... (pieces of the email...
18
by: JJ | last post by:
Now I know this question has been asked many times, but I cannot seem to find a good site which summarises the methods possible in vb .net. I am after a way of producing a unique serial number...
10
by: Laurence | last post by:
Hi there, How to differentiate between unique constraint and unique index? These are very similar but I cannot differentiate them? Could someone give me a hand? Thanks in advance
12
by: tony obrien | last post by:
Hi, I have written a Class Library in VB.net which provides Props/Meths to a caller to hide the uglinesses of a TCP message protocol between a Client and a Server. All this works just fine. ...
11
by: sqlservernewbie | last post by:
Hi Everyone, Here is a theoretical, and definition question for you. In databases, we have: Relation a table with columns and rows
6
by: pkchandra999 | last post by:
My Server OS : Centos 64 bit Apache version is Apache v2.2.9 Php Version : 5.2.5 I am providing feeds to my forum through RSS. The feeds are in html and those feeds will be parsed to bbcode...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.