AttributeError: 'ThreadClass' object has no attribute 'lb1

another wx python question I want after the thread is done getting my
data to run the populate module i keep getting :

[code]Traceback (most recent call last):
  File "C:\Python26\sign\OCTOBER 12_SERVER_syncthread.py", line 494,
in populate
    self.lb1.DeleteAllItems()
AttributeError: 'ThreadClass' object has no attribute 'lb1'[/code]

why am I getting it and how do i fix it ?

[code]class InsertData(wx.Frame):
    def __init__(self, parent, id, title):

    def populate(self):
  try:
      #load database contents'''
      self.lb1.DeleteAllItems()
      conn = lite.connect("specialeventms2011a.sqlite")
      c = conn.cursor()
      c.execute('select * from ptrecords')
      for i in c:
    index = str(i[1])
    index = self.lb1.InsertStringItem(sys.maxint, str(i[1]))
    self.lb1.SetStringItem(index, 1, str(i[2]))
    self.lb1.SetStringItem(index, 2, str(i[3]))
    self.lb1.SetStringItem(index, 3, str(i[4]))
    self.lb1.SetStringItem(index, 4, str(i[5]))
    self.lb1.SetStringItem(index, 5, str(i[6]))
    self.lb1.SetStringItem(index, 6, str(i[7]))
    self.lb1.SetStringItem(index, 7, str(i[8]))
    self.lb1.SetStringItem(index, 8, str(i[9]))
    self.lb1.SetStringItem(index, 9, str(i[10]))
    self.lb1.SetStringItem(index, 10, str(i[11]))
    self.lb1.SetStringItem(index, 11, str(i[12]))
    self.lb1.SetStringItem(index, 12, str(i[13]))

class ThreadClass(threading.Thread,InsertData):

    def run(self):

        host = ''
  port = 51269
  backlog = 5
  size = 1000000
  addr = (socket.gethostname(), port)

  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((addr))
  s.listen(backlog)
  while 1:
      client, addr= s.accept()
      data = client.recv(size)
      #print client
      if data:
    client.send(data)
    sqlite_file_to_write = open("recieved_dataII.txt", "ab" )
    sqlite_file_to_write.write(data)
    sqlite_file_to_write.close()

      client.close()
      fname="recieved_dataII.txt"
      f = open(fname, 'rb') # notice the binary mode again
      reader = csv.reader(f)
      for row in reader:
  
(Incident_number,Last_Name,First_Name,Age,Gender,Address,City,State,Zip,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,
  
Destination,Inservice,Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,Temp,Humid,Wind,TimeStamp,Refusal)
=row

    Actual_Incident_number=None

    con = lite.connect('specialeventms2011a.sqlite')
    cur = con.cursor()
    cur.execute('insert into ptrecords
values(?,?,?,?,?,?,?,?,?,?,?,?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
0)',
        (Actual_Incident_number,Incident_number, Last_Name, First_Name,
Age,Gender,Address,City,State,Zip
         ,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,Destination,Inservice,
         Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,
Temp,Humid,Wind,TimeStamp,Refusal))
    con.commit()
    cur.close()
    con.close()

      f.close()
      os.remove('recieved_dataII.txt')
      self.repopulate()
    def repopulate(self):
  InsertData.populate(self)

ThreadClass().start()

Because self, (ThreadClass), doesn't have a member lb1 but self,
(InerstData), does. Try passing it into the TheadClass when it is created.

Gadget/Steve

···

On 13/10/2011 4:18 AM, aikidoguy wrote:

another wx python question I want after the thread is done getting my
data to run the populate module i keep getting :

[code]Traceback (most recent call last):
  File "C:\Python26\sign\OCTOBER 12_SERVER_syncthread.py", line 494,
in populate
    self.lb1.DeleteAllItems()
AttributeError: 'ThreadClass' object has no attribute 'lb1'[/code]

why am I getting it and how do i fix it ?

[code]class InsertData(wx.Frame):
    def __init__(self, parent, id, title):

    def populate(self):
  try:
      #load database contents'''
      self.lb1.DeleteAllItems()
      conn = lite.connect("specialeventms2011a.sqlite")
      c = conn.cursor()
      c.execute('select * from ptrecords')
      for i in c:
    index = str(i[1])
    index = self.lb1.InsertStringItem(sys.maxint, str(i[1]))
    self.lb1.SetStringItem(index, 1, str(i[2]))
    self.lb1.SetStringItem(index, 2, str(i[3]))
    self.lb1.SetStringItem(index, 3, str(i[4]))
    self.lb1.SetStringItem(index, 4, str(i[5]))
    self.lb1.SetStringItem(index, 5, str(i[6]))
    self.lb1.SetStringItem(index, 6, str(i[7]))
    self.lb1.SetStringItem(index, 7, str(i[8]))
    self.lb1.SetStringItem(index, 8, str(i[9]))
    self.lb1.SetStringItem(index, 9, str(i[10]))
    self.lb1.SetStringItem(index, 10, str(i[11]))
    self.lb1.SetStringItem(index, 11, str(i[12]))
    self.lb1.SetStringItem(index, 12, str(i[13]))

class ThreadClass(threading.Thread,InsertData):

    def run(self):

        host = ''
  port = 51269
  backlog = 5
  size = 1000000
  addr = (socket.gethostname(), port)

  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((addr))
  s.listen(backlog)
  while 1:
      client, addr= s.accept()
      data = client.recv(size)
      #print client
      if data:
    client.send(data)
    sqlite_file_to_write = open("recieved_dataII.txt", "ab" )
    sqlite_file_to_write.write(data)
    sqlite_file_to_write.close()

      client.close()
      fname="recieved_dataII.txt"
      f = open(fname, 'rb') # notice the binary mode again
      reader = csv.reader(f)
      for row in reader:
  
(Incident_number,Last_Name,First_Name,Age,Gender,Address,City,State,Zip,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,
  
Destination,Inservice,Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,Temp,Humid,Wind,TimeStamp,Refusal)
=row

    Actual_Incident_number=None

    con = lite.connect('specialeventms2011a.sqlite')
    cur = con.cursor()
    cur.execute('insert into ptrecords
values(?,?,?,?,?,?,?,?,?,?,?,?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
0)',
        (Actual_Incident_number,Incident_number, Last_Name, First_Name,
Age,Gender,Address,City,State,Zip
         ,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,Destination,Inservice,
         Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,
Temp,Humid,Wind,TimeStamp,Refusal))
    con.commit()
    cur.close()
    con.close()

      f.close()
      os.remove('recieved_dataII.txt')
      self.repopulate()
    def repopulate(self):
  InsertData.populate(self)

ThreadClass().start()

Thanks steve but I am pretty new to not just to python but to programming in general … Im a self taught newbie…

so could you give me an example how to pass the object on creation… Thank you for you guidance

···

On Wed, Oct 12, 2011 at 10:18 PM, Gadget/Steve GadgetSteve@live.co.uk wrote:

On 13/10/2011 4:18 AM, aikidoguy wrote:

another wx python question I want after the thread is done getting my

data to run the populate module i keep getting :

[code]Traceback (most recent call last):

File “C:\Python26\sign\OCTOBER 12_SERVER_syncthread.py”, line 494,

in populate

self.lb1.DeleteAllItems()

AttributeError: ‘ThreadClass’ object has no attribute ‘lb1’[/code]

why am I getting it and how do i fix it ?

[code]class InsertData(wx.Frame):

def __init__(self, parent, id, title):
def populate(self):
  try:
      #load database contents'''
      self.lb1.DeleteAllItems()
      conn = lite.connect("specialeventms2011a.sqlite")
      c = conn.cursor()
      c.execute('select * from ptrecords')
      for i in c:
          index = str(i[1])
          index = self.lb1.InsertStringItem(sys.maxint, str(i[1]))
          self.lb1.SetStringItem(index, 1, str(i[2]))
          self.lb1.SetStringItem(index, 2, str(i[3]))
          self.lb1.SetStringItem(index, 3, str(i[4]))
          self.lb1.SetStringItem(index, 4, str(i[5]))
          self.lb1.SetStringItem(index, 5, str(i[6]))
          self.lb1.SetStringItem(index, 6, str(i[7]))
          self.lb1.SetStringItem(index, 7, str(i[8]))
          self.lb1.SetStringItem(index, 8, str(i[9]))
          self.lb1.SetStringItem(index, 9, str(i[10]))
          self.lb1.SetStringItem(index, 10, str(i[11]))
          self.lb1.SetStringItem(index, 11, str(i[12]))
          self.lb1.SetStringItem(index, 12, str(i[13]))

class ThreadClass(threading.Thread,InsertData):

def run(self):
    host = ''
  port = 51269
  backlog = 5
  size = 1000000
  addr = (socket.gethostname(), port)
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((addr))
  s.listen(backlog)
  while 1:
      client, addr= s.accept()
      data = client.recv(size)
      #print client
      if data:
          client.send(data)
          sqlite_file_to_write = open("recieved_dataII.txt", "ab"  )
          sqlite_file_to_write.write(data)
          sqlite_file_to_write.close()
      client.close()
      fname="recieved_dataII.txt"
      f = open(fname, 'rb')    # notice the binary mode again
      reader = csv.reader(f)
      for row in reader:

(Incident_number,Last_Name,First_Name,Age,Gender,Address,City,State,Zip,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,

Destination,Inservice,Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,Temp,Humid,Wind,TimeStamp,Refusal)

=row

          Actual_Incident_number=None
          con = lite.connect('specialeventms2011a.sqlite')
          cur = con.cursor()
          cur.execute('insert into ptrecords

values(?,?,?,?,?,?,?,?,?,?,?,?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,

0)',

              (Actual_Incident_number,Incident_number, Last_Name, First_Name,

Age,Gender,Address,City,State,Zip

               ,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,Destination,Inservice,
               Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,

Temp,Humid,Wind,TimeStamp,Refusal))

          con.commit()
          cur.close()
          con.close()
      f.close()
      os.remove('recieved_dataII.txt')
      self.repopulate()
def repopulate(self):
  InsertData.populate(self)

ThreadClass().start()

Because self, (ThreadClass), doesn’t have a member lb1 but self,

(InerstData), does. Try passing it into the TheadClass when it is created.

Gadget/Steve

    Thanks steve but I am pretty new to not just to python but to

programming in general … Im a self taught newbie…

    so could you give me an example how to pass the object on

creation… Thank you for you guidance

> > >
      Because self, (ThreadClass), doesn't have a member lb1 but

self,

      (InerstData), does.  Try passing it into the TheadClass when

it is created.

        Gadget/Steve
  --

  To unsubscribe, send email to

or visit

For thread programming you need to have a pattern like this:
# Imports
import thread
import wx

# Create a custom event
MyEventObject, EVT_MY_EVENT = wx.lib.newevent.NewEvent()

# Any Worker/Data Definitions - MUST NOT USE ANY GUI FUNCTIONS

# Thread Bit MUST NOT DO ANY GUI OPERATIONS but may use Workers
class MyThread():
    def __init__(self, parent, *anyotherparams*...):
        """ Called when the thread object is created!"""
        self.parent = parent # Save a reference to the parent
        self.*other*    .. = ..... # save anything else you need,

in your case lb1

    def Start(self):
        """ The Start the Thread """
        self.keepGoing = self.running = True
        thread.start_new_thread(self.Run, ())

    def Stop(self):
        """ The Stop the Thread """
        print 'Stopping!'
        self.keepGoing = False

    def IsRunning(self):
        return self.running

    def Run(self):
        """ The action part of the thread is in here. """
        while self.keepGoing:
            DoMyStuff
            evt = MyEventObject(Data=results, *OtherNamedItems*..)
            wx.PostEvent(self.parent, evt)

# GUI Bit ALL
class MyGui(wx.Frame)
    def __init__(self):
        """
        Construct my display windows here
        """
        # Bind the event to the handler
        MyThread.EVT_MY_EVENT(self, self.ResultFromThread)

    def ResultFromThread(self, evt):
        """
        Display your results in this bit, note all the Named Items

in constructor will be available as
evt.NamedItem so can be processed and/or displayed.
“”"
self.DisplayData(evt.Data)
self.DisplaySomeMore(evt.OtherNamedItem) …

    def StartBGProcess(self, evt):  # Probably triggered by a menu

item or button
self.BGThread = MyThread.MyThread(self, anyotherparams…)

    def StopBgProcess(self, evt):

        self.BGThread.Stop()

    def OnCloseWindow(self, evt):

        self.StopBgProcess(evt) # Stop the thread

        # Any other tidy up of the windows

        # may need a short sleep to let the thread finish here

       

if __name__ == "__main__":

    MyApp =  wx.PySimpleApp()

    frame = MyGui()

    frame.Show()

    MyApp.MainLoop()

    # Any processing to do after window close is done here
···

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

If lb1 is a wx widget of some sort, then do NOT interact with it directly from the thread itself. Widget methods should only be called from the main GUI thread. See also wiki.wxpython.org/LongRunningTasks

If you do, you’ll probably end up having some other weird issues.

···

Mike Driscoll

Blog: http://blog.pythonlibrary.org

Clay Richmond wrote:

Thanks steve but I am pretty new to not just to python but to
programming in general ... Im a self taught newbie...
so could you give me an example how to pass the object on creation.

Did you call InsertData.__init__ in your ThreadClass __init__
function? Unlike C++, base class constructors are not automatically
called in Python. You have to do it yourself.

However, as Mike said earlier, this design is asking for trouble. It IS
possible to create windows in a secondary thread, but to do so you must
have an event loop in that thread to dispatch the window events.
Without the event loop, your window can't even be created. Many people
believe that there is one single event queue per application, and all
events go to that unified queue. That's not true. An event queue is
actually associated with a thread. The events for a window are sent to
the queue for the thread that created the window. So, every thread that
creates a window must be running a message loop.

For a newbie, you should keep all of your windows in the main thread so
the events are dispatched by your main message loop. When you need to
interact with the UI from a secondary thread, send a message.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

I think thats where i wasn’t clear and I do appologize … Im a self taught newbie so I don’t alway undersatnd all the terms… I am collecting data in my thread and loading it into my data base thats all… I want the list control to auto refresh when the data is done being transferred and that is in my main thread where all my other GUI stuff is … otherwise I have to hit the enter button and it adds and empty line … so I was simply trying to call the module in the main thread that has my event loops and what not… its alot of code so I tried to post the code that was giving the problem … That is my question if I calling the module in the main thread why am I getting that error and admittedly I am 100% confused now … any help or examples you can point me too is appreciated

···

On Thu, Oct 13, 2011 at 10:06 AM, Tim Roberts timr@probo.com wrote:

Clay Richmond wrote:

Thanks steve but I am pretty new to not just to python but to

programming in general … Im a self taught newbie…

so could you give me an example how to pass the object on creation.

Did you call InsertData.init in your ThreadClass init

function? Unlike C++, base class constructors are not automatically

called in Python. You have to do it yourself.

However, as Mike said earlier, this design is asking for trouble. It IS

possible to create windows in a secondary thread, but to do so you must

have an event loop in that thread to dispatch the window events.

Without the event loop, your window can’t even be created. Many people

believe that there is one single event queue per application, and all

events go to that unified queue. That’s not true. An event queue is

actually associated with a thread. The events for a window are sent to

the queue for the thread that created the window. So, every thread that

creates a window must be running a message loop.

For a newbie, you should keep all of your windows in the main thread so

the events are dispatched by your main message loop. When you need to

interact with the UI from a secondary thread, send a message.

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Clay Richmond wrote:

I think thats where i wasn't clear and I do appologize ... Im a self
taught newbie so I don't alway undersatnd all the terms...

There is no need to apologize. We were all newbies once. At least,
they tell me I was; I've blocked it out so I can pretend I was always
omniscient.

I am collecting data in my thread and loading it into my data base
thats all... I want the list control to auto refresh when the data is
done being transferred and that is in my main thread where all my
other GUI stuff is ... otherwise I have to hit the enter button and it
adds and empty line .... so I was simply trying to call the module in
the main thread that has my event loops and what not... its alot of
code so I tried to post the code that was giving the problem ... That
is my question if I calling the module in the main thread why am I
getting that error and admittedly I am 100% confused now ... any help
or examples you can point me too is appreciated

By making the ThreadClass derive from InsertData, you're not saying "my
thread needs to communicate with that window. You're saying "this
thread IS a window." That's not what you want.

Instead, your main window should create the InsertData window. Then,
pass that window object into your thread. Now you can call PostEvent to
send an event to that object requesting your repopulating. You can even
create custom events to do that. Sketchy example:

    import wx.lib.newevent
    RepopulateEvent, EVT_REPOPULATE = wx.lib.newevent.NewEvent()
    ...
    class InsertData(...):
        def __init__(...):
            self.Bind( EVT_REPOPULATE, self.onRepopulate )
    ....
    class ThreadClass( ... ):
        def __init__( self, uiwindow=None ):
            self.uiWindow = uiwindow;

        def long_process( self ):
            # Notify the user interface.
            wx.PostEvent( self.uiWindow, RepopulateEvent( ... ) )

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

this is where I am so far … can you give me your feed back ?

import wx.lib.newevent

Repopulate,EVT_REPOPULATE = wx.lib.newevent.NewEvent()

class InsertData(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self, parent, id, title, size=(990,668),style=wx.DEFAULT_FRAME_STYLE|wx.WS_EX_CONTEXTHELP)

self.Bind(EVT_REPOPULATE, self.onRepopulate)

self.lb1 = wx.ListCtrl(panel, -1, (380,360), size=(600,210), style=wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES, name = “listCtrl”)
self.lb1.InsertColumn(0, “Ic Num”,format=wx.LIST_FORMAT_LEFT, width=-1)
self.lb1.InsertColumn(1, “Last Name”,format=wx.LIST_FORMAT_LEFT, width=-1)
self.lb1.InsertColumn(2, “First Name”,format=wx.LIST_FORMAT_LEFT, width=-1)
self.lb1.InsertColumn(3, “Age”,format=wx.LIST_FORMAT_LEFT, width=-1)
self.lb1.InsertColumn(4, “Gender”,format=wx.LIST_FORMAT_LEFT, width=-1)
self.lb1.InsertColumn(5, “Address”,format=wx.LIST_FORMAT_LEFT, width=-1)
self.lb1.InsertColumn(6, “City”,format=wx.LIST_FORMAT_LEFT, width=-1)
self.lb1.InsertColumn(7, “State”,format=wx.LIST_FORMAT_LEFT, width=-1)
def repopulate(self,event):
self.populate()
def populate(self):

 #load database contents'''
 self.lb1.DeleteAllItems()
 conn = lite.connect("specialeventms2011a.sqlite")
 c = conn.cursor()
 c.execute('select * from ptrecords')
 for i in c:

index = str(i[1])
index = self.lb1.InsertStringItem(sys.maxint, str(i[1]))
self.lb1.SetStringItem(index, 1, str(i[2]))
self.lb1.SetStringItem(index, 2, str(i[3]))
self.lb1.SetStringItem(index, 3, str(i[4]))
self.lb1.SetStringItem(index, 4, str(i[5]))
self.lb1.SetStringItem(index, 5, str(i[6]))
self.lb1.SetStringItem(index, 6, str(i[7]))
self.lb1.SetStringItem(index, 7, str(i[8]))

class ThreadClass (threading.Thread):
def init(self, parent, event):
self.parent = parent
self.event = event
threading.Thread.init(self)
def run(self):

host = ‘’
port = 51269
backlog = 5
size = 1000000
addr = (socket.gethostname(), port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((addr))
s.listen(backlog)
while 1:
client, addr= s.accept()
data = client.recv(size)
if data:
client.send(data)
sqlite_file_to_write = open(“recieved_dataII.txt”, “ab” )
sqlite_file_to_write.write(data)
sqlite_file_to_write.close()

 client.close()
 wxPostEvent(self.Parent,RepopulateEvent())
 self.repopulate(self)

def repopulate(self):
InsertData.populate(self)

···

On Wed, Oct 12, 2011 at 8:18 PM, aikidoguy clayrichmond1@gmail.com wrote:

another wx python question I want after the thread is done getting my

data to run the populate module i keep getting :

[code]Traceback (most recent call last):

File “C:\Python26\sign\OCTOBER 12_SERVER_syncthread.py”, line 494,

in populate

self.lb1.DeleteAllItems()

AttributeError: ‘ThreadClass’ object has no attribute ‘lb1’[/code]

why am I getting it and how do i fix it ?

[code]class InsertData(wx.Frame):

def __init__(self, parent, id, title):







def populate(self):

    try:

        #load database contents'''

        self.lb1.DeleteAllItems()

        conn = lite.connect("specialeventms2011a.sqlite")

        c = conn.cursor()

        c.execute('select * from ptrecords')

        for i in c:

            index = str(i[1])

            index = self.lb1.InsertStringItem(sys.maxint, str(i[1]))

            self.lb1.SetStringItem(index, 1, str(i[2]))

            self.lb1.SetStringItem(index, 2, str(i[3]))

            self.lb1.SetStringItem(index, 3, str(i[4]))

            self.lb1.SetStringItem(index, 4, str(i[5]))

            self.lb1.SetStringItem(index, 5, str(i[6]))

            self.lb1.SetStringItem(index, 6, str(i[7]))

            self.lb1.SetStringItem(index, 7, str(i[8]))

            self.lb1.SetStringItem(index, 8, str(i[9]))

            self.lb1.SetStringItem(index, 9, str(i[10]))

            self.lb1.SetStringItem(index, 10, str(i[11]))

            self.lb1.SetStringItem(index, 11, str(i[12]))

            self.lb1.SetStringItem(index, 12, str(i[13]))

class ThreadClass(threading.Thread,InsertData):

def run(self):



    host = ''

    port = 51269

    backlog = 5

    size = 1000000

    addr = (socket.gethostname(), port)



    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    s.bind((addr))

    s.listen(backlog)

    while 1:

        client, addr= s.accept()

        data = client.recv(size)

        #print client

        if data:

            client.send(data)

            sqlite_file_to_write = open("recieved_dataII.txt", "ab"  )

            sqlite_file_to_write.write(data)

            sqlite_file_to_write.close()



        client.close()

        fname="recieved_dataII.txt"

        f = open(fname, 'rb')    # notice the binary mode again

        reader = csv.reader(f)

        for row in reader:

(Incident_number,Last_Name,First_Name,Age,Gender,Address,City,State,Zip,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,

Destination,Inservice,Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,Temp,Humid,Wind,TimeStamp,Refusal)

=row

            Actual_Incident_number=None



            con = lite.connect('specialeventms2011a.sqlite')

            cur = con.cursor()

            cur.execute('insert into ptrecords

values(?,?,?,?,?,?,?,?,?,?,?,?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,

0)',

                (Actual_Incident_number,Incident_number, Last_Name, First_Name,

Age,Gender,Address,City,State,Zip

                 ,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,Destination,Inservice,

                 Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,

Temp,Humid,Wind,TimeStamp,Refusal))

            con.commit()

            cur.close()

            con.close()



        f.close()

        os.remove('recieved_dataII.txt')

        self.repopulate()

def repopulate(self):

    InsertData.populate(self)

ThreadClass().start()

Clay Richmond wrote:

this is where I am so far ... can you give me your feed back ?

I think you have the general idea. You have to fix the use of
"self.parent" and "self.Parent" in the ThreadClass. Plus, you are going
to want to delete these lines:
        self.repopulate(self)
    def repopulate(self):
        InsertData.populate(self)

Other than that, I think you are on the right track.

BTW, there is a SocketServer module in the Python library that could
help with your thread's work.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

the thuds you hear is my head beating against the table… myThreadClass().start() worked before my changes and keep asking for 3 arguments… I’ve tried every argument I can think of but I keep getting various error … can someone help and explain thanks in advance

TypeError: init() takes exactly 3 arguments (1 given)
File “C:\Python26\sign\OCTOBER 13_Server_pyevent.py”, line 6799, in
ThreadClass().start()

class ThreadClass(threading.Thread):
def init(self, parent, event):
self.parent = parent
self.event = event
threading.Thread.init(self)

def run(self):

host = ‘’
port = 51269
backlog = 5
size = 1000000
addr = (socket.gethostname(), port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((addr))
s.listen(backlog)
while 1:
client, addr= s.accept()
data = client.recv(size)
if data:
client.send(data)
sqlite_file_to_write = open(“recieved_dataII.txt”, “ab” )
sqlite_file_to_write.write(data)
sqlite_file_to_write.close()

 client.close()
 fname="recieved_dataII.txt"
 f = open(fname, 'rb')    # notice the binary mode again
 reader = csv.reader(f)
 for row in reader:

(Incident_number,Last_Name,First_Name,Age,Gender,Address,City,State,Zip,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,
Destination,Inservice,Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,Temp,Humid,Wind,TimeStamp,Refusal) =row

Actual_Incident_number=None

con = lite.connect(‘specialeventms2011a.sqlite’)
cur = con.cursor()
cur.execute(‘insert into ptrecords values(?,?,?,?,?,?,?,?,?,?,?,?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0)’,
(Actual_Incident_number,Incident_number, Last_Name, First_Name, Age,Gender,Address,City,State,Zip
,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,Destination,Inservice,
Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather, Temp,Humid,Wind,TimeStamp,Refusal))
con.commit()
cur.close()
con.close()

 f.close()
 open('recieved_dataII.txt','w').close
 wxPostEvent(self.prent,RepopulateEvent())

ThreadClass().start()

···

On Thu, Oct 13, 2011 at 2:52 PM, Tim Roberts timr@probo.com wrote:

Clay Richmond wrote:

this is where I am so far … can you give me your feed back ?

I think you have the general idea. You have to fix the use of

“self.parent” and “self.Parent” in the ThreadClass. Plus, you are going

to want to delete these lines:

    self.repopulate(self)

def repopulate(self):

    InsertData.populate(self)

Other than that, I think you are on the right track.

BTW, there is a SocketServer module in the Python library that could

help with your thread’s work.

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

The line above is actually calling 1) ThreadClass.init() then
with the returned result start() - if you split it out to:

myThread = ThreadClass(self, None)

myThread.start()

it should run once you provide a start member - (The None is

because I can not see any use of Event but if I am wrong you will
need to provide an appropriate event). At least you will get a
sensible error message, (no start member), unless the base class
provides a start.

General principle - if a line has multiple function calls on it and

is giving an error message it is almost always worth splitting it
into separate operations - my own personal rule for clear,
maintainable code is to do the same all the time. Leads to a higher
line count but means only one thing going on on a line so only one
thing to go wrong.

Gadget/Steve 06:15

Gadget/Steve
···

On 14/10/2011 4:22 AM, Clay Richmond wrote:

    the thuds you hear is my head beating against the table....

myThreadClass().start() worked before my changes and keep asking
for 3 arguments… I’ve tried every argument I can think of but
I keep getting various error … can someone help and explain
thanks in advance

TypeError: init() takes exactly 3 arguments (1 given)

    File "C:\Python26\sign\OCTOBER 13_Server_pyevent.py", line 6799,

in

      ThreadClass().start()

class ThreadClass(threading.Thread):

        def __init__(self, parent, event):

            self.parent = parent

            self.event = event

            threading.Thread.__init__(self)

       

        def run(self):

host = ‘’
port = 51269
backlog = 5
size = 1000000
addr = (socket.gethostname(), port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((addr))
s.listen(backlog)
while 1:
client, addr= s.accept()
data = client.recv(size)
if data:
client.send(data)
sqlite_file_to_write = open(“recieved_dataII.txt”, “ab” )
sqlite_file_to_write.write(data)
sqlite_file_to_write.close()

         client.close()
         fname="recieved_dataII.txt"
         f = open(fname, 'rb')    # notice the binary mode again
         reader = csv.reader(f)
         for row in reader:
      
      (Incident_number,Last_Name,First_Name,Age,Gender,Address,City,State,Zip,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,

      Destination,Inservice,Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,Temp,Humid,Wind,TimeStamp,Refusal)

=row

      Actual_Incident_number=None
      
      con = lite.connect('specialeventms2011a.sqlite')
      cur = con.cursor()
      cur.execute('insert into ptrecords

values(?,?,?,?,?,?,?,?,?,?,?,?, ?,
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0)',
(Actual_Incident_number,Incident_number, Last_Name,
First_Name, Age,Gender,Address,City,State,Zip

,Ailment,Treatment,Patient_reprt,Initial_contact,Hospital,Destination,Inservice,
Provider_1,Provider_2,Sys,Dia,Pulse,Resp,Weather,
Temp,Humid,Wind,TimeStamp,Refusal))
con.commit()
cur.close()
con.close()

         f.close()
         open('recieved_dataII.txt','w').close
         wxPostEvent(self.prent,RepopulateEvent())
    ThreadClass().start()

Great worker thread template Steve! Thanks

I'd like your opinion on this addition:

One thing I've done in general with the startup block
at the bottom, is put the call to Main() or MainLoop()
in a try..except block.

if __name__ == "__main__":
MyApp = wx.PySimpleApp()
frame = MyGui()
frame.Show()
    try:
    MyApp.MainLoop()
    except:
       # Do something about unexpected exits from main loop
       raise # and optionally re-raise exception

\# Any processing to do after window close is done here

Is this overly paranoid?

Rufus

···

On Oct 13, 4:11 am, Gadget/Steve <GadgetSt...@live.co.uk> wrote:

For thread programming you need to have a pattern like this:

<Code Snipped>

You probably will not see any exceptions coming from within MainLoop because Python exceptions are not passed over the C++ layers in the stack. See C++ & Python Sandwich - wxPyWiki

···

On 10/27/11 8:40 AM, Rufus wrote:

On Oct 13, 4:11 am, Gadget/Steve<GadgetSt...@live.co.uk> wrote:

For thread programming you need to have a pattern like this:

<Code Snipped>

Great worker thread template Steve! Thanks

I'd like your opinion on this addition:

One thing I've done in general with the startup block
at the bottom, is put the call to Main() or MainLoop()
in a try..except block.

if __name__ == "__main__":
     MyApp = wx.PySimpleApp()
     frame = MyGui()
     frame.Show()
     try:
        MyApp.MainLoop()
     except:
        # Do something about unexpected exits from main loop
        raise # and optionally re-raise exception

     # Any processing to do after window close is done here

Is this overly paranoid?

--
Robin Dunn
Software Craftsman