English 中文(简体)
睡觉是否阻止接触物体的变数?
原标题:Does sleep() in python prevent access to an object s variables?
  • 时间:2010-12-29 23:41:12
  •  标签:
  • python
  • sleep

我的反对是采取行动,然后在再次采取行动之前睡觉第二次。 然而,该物体有各种变数,无论在第二个睡眠期,均须随时取用。 当目标执行被中止时,其变量是否无法使用?

这是一种 Python。

感谢。

EDIT 1: Clarifying inaccessible :

Object A has variable x that Object B needs to access repeatedly. Object A sleeps for 1 second. Will there be a problem if Object B tries to use x while A is sleeping?

EDIT 2: Forgot to mention the two objects are running as individual processes (I m using processes to avoid the GIL)

EDIT:

class QueueController(Process):
    def __init__(self):
        Process.__init__(self)
        self.queue_stream    = Queue()
        self.queue_language  = Queue()
        self.queue_expander  = Queue()
        self.queue_feature   = Queue()
        self.queue_classify  = Queue()
        self.db = connect_to_db()

    def run(self):
        # Every second, allow 10 more tweets from the raw_tweets db
        # enter the queue_stream to be processed
        value = 0
        while True:
            for i in db.raw_tweets.find().skip(value).limit(30):
                self.queue_stream.put(i)
                value+=30
                sleep(1)

是否还有另一个使用这一奎埃勒舱位的物体仍然能够使用电线——变量,即使它睡了二次吗? 恐怕睡觉会停止处决,但也会接触这些格言——作为一方影响的变量。

最佳回答

<代码>时间.sleep(>> 确实释放了GIL,因此允许其他校对运行。

我之所以作出这一回答,而不是回答你提出的问题,是因为你提出的问题毫无意义。 除了其他透镜的运行能力之外,没有其他途径。

问题回答

Never touched much on python but still I think I do know the answer. The thing is: there are any threads other than main? If the answer is yes, then they are accessible (watch out for racing conditions here), since a thread can go to sleep but the others are still active. If you don t have any other threads, then you won t be able to do much, since the main thread is sleeping, so nothing much will happen.

EDIT:

目标A有变数x,目标B需要反复接触。 反对A 睡觉1秒。 如果目标B试图在A睡觉时使用x,是否会出现问题?

正如有人已经说过的那样,物体不去睡觉,read子就行了。 因此,如果你对B有不同的视线和A要睡觉,那么你就可以从B处获得A所认为的(如果不是的话)主线(我假定A在主线上运行)将睡觉,而不会发生任何情况。 如果你怀疑底线是什么,请查看:http://en.wikipedia.org/wiki/Thread_%28computer_science%29。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签