2
votes
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

2 Answers

2
votes

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

-1
votes

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