2
 import os, sys, time from threading import Thread from threading import currentThread import SimpleXMLRPCServer servAddr = ("localhost", 8000) serv = SimpleXMLRPCServer.SimpleXMLRPCServer(servAddr) tt = [] import SimpleXMLRPCServer class myThread(Thread): def __init__ (self,p): self.p = p Thread.__init__(self) def run (self): t = currentThread() while 1: n = random.random() tt[self.p] = self.p + '!!!' time.sleep(n) def rn(): mythreads = [] for p in (1,2,3): t = myThread(p) mythreads.append(t) t.start() return 1 def test(): return tt serv.register_function(rn) serv.register_function(test) serv.register_introspection_functions() 

2 Answers 2

2

Python objects like dict are already thread safe, so in that sense your script is already thread safe. What other specific thing you want to make thread safe, at-least for now it looks ok

Sign up to request clarification or add additional context in comments.

2 Comments

may need to lock tt for writing or not ? docs.python.org/release/2.5.2/lib/condition-objects.html
@Bdfy , no objects like dict are already threadsafe for such operation, if you were doing some complex calculations involving multiple objects then you should think about locks, semaphores etc
-2

I am not really familiar with python, but can't you use Semaphores / Monitors for atomic insurance?

1 Comment

... that's exactly what I would expect an answer here to tell me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.