Spaces:
Sleeping
Sleeping
File size: 1,072 Bytes
3d4ad9a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import sys
import os
import threading
import sqlite3
import uuid
# add parent dir
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import env
e = env.ETLEnv(difficulty="hard")
obs = e.reset()
edits = [
{"target_line": 6, "new_code": 'conn = sqlite3.connect("etl_target.db", check_same_thread=False)\nglobal_lock = threading.Lock()\n'},
{"target_line": 14, "new_code": ' try:\n with global_lock:\n cursor.execute("INSERT INTO events (worker_id, event_no) VALUES (?, ?)", (worker_id, i))\n conn.commit()\n'},
{"target_line": 15, "new_code": ""},
{"target_line": 16, "new_code": ""},
{"target_line": 17, "new_code": ""},
{"target_line": 18, "new_code": ""},
{"target_line": 19, "new_code": ""}
]
for ed in edits:
action = env.EditCodeAction(filepath="pipeline.py", target_line=ed["target_line"], new_code=ed["new_code"])
e.step(action)
with open(e._workspace / "pipeline.py", "r") as f:
for i, line in enumerate(f, 1):
print(f"{i:2}: {repr(line)}")
e.close()
|