multithreading - Unable to access variables after creating a daemon thread in python -
this first program in threading , new os concepts. trying understand how asynchronously stuffs using python. trying establish a session , send keepalives on daemon thread , send protocol messages using main thread. noticed once created thread unable access variables able access before creating thread. not see global variables used see before created new thread.
can 1 me understand how threading working here. trying understand:
- how print logging useful.
- how kill thread created?
how access variables 1 thread
def pcep_init(ip): global pcc_client,keeppkt,pkt,thread1 accept_connection(ip) send_pcep_open() # create new daemon thread send ka thread1 = mythread(1, "keepalive-thread\r") thread1.setdaemon(true) # start new threads print "this thread1 before start %r" % thread1 thread1.start() print "this thread1 after start %r" % thread1 print "coming out of pcep_init" return 1
however when executed api see print not kind of misaligned due async
>>> ret_val=pcep_init("192.168.25.2"). starting pce server on 192.168.25.2 port 4189 connection ('192.168.25.1', 42352) , initial daemon)>fore start <mythread(keepalive-thread , started daemon 140302767515408)>ead(keepalive-thread coming out of pcep_init >>> starting keepalive-thread <------ supposed hit enter button python prompt not sure why thats needed. >>> thread1 traceback (most recent call last): file "<console>", line 1, in <module> nameerror: name 'thread1' not defined >>> threading.currentthread() <_mainthread(mainthread, started)> >>> threading.activecount() 2 >>> threading.enumerate() <-------------- not sure why not showing main thread , started daemon 140302767515408)>], <mythread(keepalive-thread >>>
Comments
Post a Comment