Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40957

Re: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads

Date 2013-03-09 10:35 -0600
From Andrew Berg <bahamutzero8825@gmail.com>
Subject Re: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads
References <f9f28b67-cf81-4d9e-96fd-fe4e75fb8c9c@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3132.1362846957.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 2013.03.09 09:26, Owatch wrote:
> Thing is, when I run the program. Nothing happens. 
> 
> Can somebody help point out what is wrong? (I've asked questions and researched for 3 days, without getting anywhere, so I did try)
You defined a thread, but never created or started it. Also, why did you
subclass threading.Thread? You also mentioned queues, but you didn't use
them.

Not tested, but shows the basics:

import threading
import queue
import socket

def process():
  while alive:
    thing = things_to_process.get()
    # do stuff with the thing here
    things_to_process.task_done()

alive = True
host = 'localhost'
port = 9999
things_to_process = queue.Queue()
process_thread = threading.Thread(target=process)
process_thread.start()
sock = socket.socket()
sock.connect((host, port))
while alive:
  try:
    data = sock.recv()
  except Exception: # should probably do different things for different
errors in real code
    alive = False
    sock.close()
    process_thread.join()
    raise
  else:
    things_to_process.put(data)

-- 
CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads Owatch <charles.xrandolph2@gmail.com> - 2013-03-09 07:26 -0800
  Re: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads Andrew Berg <bahamutzero8825@gmail.com> - 2013-03-09 10:35 -0600
    Re: http://stackoverflow.com/questions/15311450/my-chat-client-freezes-up-after-beginning-threads Owatch <charles.xrandolph2@gmail.com> - 2013-03-09 13:23 -0800

csiph-web