0

I'm not really that knowledgeable about thread-safe vs non-thread-safe operations but am wondering if a problem I'm seeing might be because of that.

In my modules directory I've created a module that has a class defined.

Then in db.py I have an _after_insert trigger like so:

db.workorder._after_insert.append(lambda s,f: workorderAfterInsert(s,f))

In my _after_insert trigger I'm instantiating the class from my module like this:

import workorder.sequencer as sequencer

workorderId = id
wo = db.workorder(workorderId)

sequencer = sequencer.Sequencer(workorder_id=workorderId, db=db)
sequencer.build_bom()
sequencer.sequence()
sequencer.save_sequenced_workorder()

db.commit()

I'm not sure how to describe it, but I'm seeing random errors popping up in the execution of sequencer.sequence(). My only thought at this point is that there are thread-safe or concurrency issues going on.

I'd really appreciate it if someone could tell me whether or not this is safe (or wise). Any input would be appreciated.

-Jim

Jim
  • 21
  • 3
  • What is `sequencer` and where/how is `db` defined? Please show more of the relevant code. – Anthony Jul 22 '15 at 22:37
  • Can't really tell if you do not show how the code interacts. – Hans Then Jul 22 '15 at 22:38
  • 1
    @Anthony - Sequencer is just a class I've written and stored in the modules directory. If you think it is relevant I can post here. – Jim Jul 22 '15 at 22:54
  • I just found this: http://stackoverflow.com/questions/8309902/are-python-instance-variables-thread-safe I think my problem may be that I had all my variables as 'class' variables instead of instances variables (which was what I thought I was getting). I've implemented the change and will see if this works better. – Jim Jul 22 '15 at 23:05

1 Answers1

0

My problem was that I had my variables defined as class variables instead of instance variables. Changed that up and now it all works.

Jim
  • 21
  • 3