python: how to send packets in multi thread and then the thread kill itself

后端 未结 7 1579
忘掉有多难
忘掉有多难 2020-12-03 12:40

I have a question. I\'d like to send a continuous streams of byte to some host for certain amount of time (let\'s say 1 minute) using python.

Here is my code so far

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 13:19

    It's easy to test the scope of killed:

    >>> import thread
    >>> killed = False
    >>> import time
    >>> def test():
    ...  while True:
    ...   time.sleep(1)
    ...   if killed:
    ...     print 'Dead.'
    ...     break
    ... 
    >>> thread.start_new_thread(test, ())
    25479680
    >>> time.sleep(3)
    >>> killed = True
    >>> Dead.
    

提交回复
热议问题