본문 바로가기

Programming/python38

[python] thread mangement 파이썬에서 여러개의 쓰레드를 만질때 Thread안에서 새로운 Thread를 돌리면 부모쓰레드의 특정 지점에서 자식쓰레드를 만들고, 자식쓰레드가 도는 동안 부모 쓰레드는 진행되지 않는다. 그래서 당연히 이렇게 하면 안된다. Thread는 똑같은 부모수준에서 만들어 놓고 순서는 locking방법을 이용해서 해야한다. https://docs.python.org/2/library/threading.html http://www.laurentluce.com/posts/python-threads-synchronization-locks-rlocks-semaphores-conditions-events-and-queues/comment-page-1/ 두번째 링크에 개념과 예제가 잘 설명 되어있다. 난 semaphore 사.. 2014. 6. 27.
[python] python 의 변수들 파이썬은 C 와는 다르게 기본적으로 변수가 가르키는 것은 모두 reference개념이다. 포인터의 개념과 같다. 즉A = [ 1 2 3 ]B = AC = A B[0] = 4 이렇게 하면 A[0]과 C[0]도 모두 4로 바뀌게 된다. A, B, C 는 모두 같은 변수를 가르키는 주소이다. 같은 메모리를 가르키고 있는지 확인하는 python명령어인 is 를 사용해서 확인해 볼수 있다. A is BA is CB is C모두 True가 반환된다. 그러면 A와 B가 같은 내용을 담고 다른 메모리번지를 가르키게 하려면 어떻게 해야 할까? B = A[:] C = A[:]이렇게 해주면된다. 리스트의 전체를 가르키는 :를 사용해 줌으로서 가능하다. A의 전체내용을 B에 넣으란 뜻이다. 아니면, import copy fr.. 2014. 2. 25.
[python] variable 이 존재하는지 check 하는 방법 http://stackoverflow.com/questions/9748678/which-is-the-best-way-to-check-for-the-existence-of-an-attribute Which is a better way to check for the existence of an attribute?Jarret Hardie provided this answer:if hasattr(a, 'property'): a.propertyI see that it can also be done this way:if 'property' in a.__dict__: a.propertyIs one approach typically used more than others? There is no "best" way, b.. 2014. 2. 25.
python thread http://www.tutorialspoint.com/python/python_multithreading.htm Running several threads is similar to running several different programs concurrently, but with the following benefits: Multiple threads within a process share the same data space with the main thread and can therefore share information or communicate with each other more easily than if they were separate processes.Threads sometimes .. 2013. 8. 21.