What do you suggest then? This part work? the problem is inside if
script.sc_status == 11:
On Tuesday, February 10, 2015 at 2:21:13 PM UTC+1, Niphlod wrote:
>
> oh please DON'T chdir ! it's not thread safe
>
> On Tuesday, February 10, 2015 at 11:19:18 AM UTC+1, Yebach wrote:
>>
>> Hello
>> I encounter an interesting problem or bug
>>
>> I have a app that runs some *.exe program that returns a file (*.out) to
>> be processed every couple of second.
>> If I want to stop this exe from working I delete *.lls file.
>> So if a user hits play button I create lls file put it in a directory,
>> sets status in db to 11 and then after some calculation is done user clicks
>> on stop button and lls file is deleted, status in db is set back to 10, and
>> some more actions are done with out file (doesn't really matter)
>>
>> NOW HERE IS THE CATCH
>>
>> If I run web2py from eclipse it works fine
>>
>> if I run web2py as standalone so doble click on web2py.py file in my
>> windows explorer the lls file is not deleted, BUT there is a catch. If I
>> refresh the page, click the stop button in my webapp lls file is deleted
>>
>> ANY suggestions?
>>
>> BTW there are no errors
>>
>> here is my code
>>
>>
>> id = (request.vars.id)
>> try:
>> path = os.path.join(request.folder, 'engine')
>> llsPath = os.path.join(request.folder, 'engine', 'e1',
>> request.vars.id + '.lls')
>>
>> data = db(getDbScript(db(getDbScript(request.vars.id)).select(
>> db.scripts.id, db.scripts.sc_lls, db.scripts.sc_engine_output,
>> db.scripts.sc_status, db.scripts.sc_menu_data).first())).select(
>> db.scripts.id, db.scripts.sc_lls, db.scripts.sc_engine_output,
>> db.scripts.sc_status, db.scripts.sc_menu_data).first()
>> script = db(getDbScript(request.vars.id)).select(db.scripts.id,
>> db.scripts.sc_lls, db.scripts.sc_engine_output, db.scripts.sc_status,
>> db.scripts.sc_menu_data,db.scripts.sc_organization,
>> db.scripts.sc_cal_start).first()
>> org = script["sc_organization"]
>> shifts = db(db.shifts.sh_organisation ==
>> org).select(db.shifts.sh_code,
>> db.shifts.sh_start1,db.shifts.sh_start2,db.shifts.sh_end1,db.shifts.sh_end2,db.shifts.sh_color,db.shifts.sh_length1,db.shifts.sh_length2).as_list()
>> outPath = os.path.join(request.folder, 'engine', 'e1',
>> request.vars.id + '.out')
>>
>> if not script:
>> return dict(status = -1)
>>
>> ###Status = 11 - Script is being calculated
>> if script.sc_status == 11:
>>
>>
>> # Change status - status = 10 --> user lahko da skripo
>> računat - nima napak oz pomanjklivih podatkov
>> #, sc_engine_output = readOutFile(request.vars.id))s
>> # Add when user stopped calculation (ce bojo problemi se bo
>> zraven posiljalo tudi id od script activitya)
>> #Odstranim lls datoteko --> engine preneha delovat
>> if os.path.isfile(llsPath):
>> os.remove(llsPath)
>>
>> activity = db(db.script_activity.sa_id_script ==
>> request.vars.id).select(db.script_activity.id,
>> db.script_activity.sa_stop, orderby = ~db.script_activity.id, limitby =
>> (0, 1)).first()
>> activity.update_record(sa_stop = 'now')
>> script.update_record(sc_status = 10)
>>
>>
>> ##če obstaja out datotkea
>> if os.path.isfile(outPath):
>> #preberemo fajl
>> out = readOutFile(request.vars.id).split('\n')
>> #Vnesemo podatke v tabelo script
>> script.update_record(sc_engine_output = readOutFile(
>> request.vars.id))
>> #odstranim out. datoteko
>> os.remove(outPath)
>> workersDb = db(db.workers.w_organisation == org).select(
>> db.workers.id, db.workers.w_nick_name).as_list()
>> #sparsamo out datoteko da jo lahko damo v tabelo result
>> dateStart = script["sc_cal_start"]
>> resultData = parseOut(out, dateStart, shifts, workersDb,
>> org)
>> #Pišemo rezultate v tabelo results
>> resultsDbInsert(resultData["resultsDbData"], org, id)
>>
>>
>> return dict(status = 1)
>>
>>
>> else:
>>
>> ##prevedemo skripto v id.lls, prav tako zapišemo še v sc_lls
>> #
>> db.script_activity.insert(sa_id_script = request.vars.id,
>> sa_start = 'now');
>>
>> ##validiramo json če ima kakršne koli napake idt.
>> valJson = validateJson(script.sc_menu_data)
>> if 1!=1 :#not valJson:
>> #validacija ni uspela vrnemo error 300
>> return dict(status = 300)
>> #$#nov json - z vsemi errorji zapiđšemo v sc_menu_data
>> script.update_record(sc_menu_data = valJson["formJson"])
>> #če obstajjo errorji pol konc
>> if 1!=1:#valJson["errors"]:
>> #skripta gre v status 91, kar pomen da je user ne more
>> dat računat
>> script.update_record(sc_status = 91)
>> #print valJson["errors"]
>> return dict(status = 200)
>>
>> else:
>> script.update_record(sc_status = 11)
>> if os.path.isfile(outPath):
>> os.remove(outPath)
>> TranslateData(script.sc_menu_data, path, id, org)
>> # Run woshi engine
>> path_1 = os.path.join(path, 'e1')
>> os.chdir(path_1)
>> #p = subprocess.Popen(['w_parameter.bat', id],
>> shell=True, stdout = subprocess.PIPE)
>> p = subprocess.Popen(['woshi_engine.exe', id],
>> shell=True, stdout = subprocess.PIPE)
>> return dict(status = 1)
>>
>> except Exception as e:
>> script.update_record(sc_status = 10)
>> exc_type, exc_obj, exc_tb = sys.exc_info()
>> fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
>>
>> print(exc_type, fname, exc_tb.tb_lineno)
>> print e.__doc__
>> print e.message
>>
>> return dict(status = 666)
>>
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.