oocana-python-executor 0.16.10__tar.gz → 0.16.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/PKG-INFO +1 -1
  2. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/pyproject.toml +1 -1
  3. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/executor.py +18 -28
  4. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/__init__.py +0 -0
  5. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/block.py +0 -0
  6. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/context.py +0 -0
  7. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/data.py +0 -0
  8. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/hook.py +0 -0
  9. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/logger.py +0 -0
  10. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/matplot/matplotlib_oomol/__init__.py +0 -0
  11. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/matplot/matplotlib_oomol/oomol.py +0 -0
  12. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/matplot/oomol_matplot_helper.py +0 -0
  13. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/secret.py +0 -0
  14. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/service.py +0 -0
  15. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/topic.py +0 -0
  16. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/python_executor/utils.py +0 -0
  17. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/tests/test_cli.py +0 -0
  18. {oocana_python_executor-0.16.10 → oocana_python_executor-0.16.12}/tests/test_secret.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oocana-python-executor
3
- Version: 0.16.10
3
+ Version: 0.16.12
4
4
  Summary: a client subscribe mqtt topic to execute oocana's block
5
5
  Author-Email: l1shen <lishen1635@gmail.com>, yleaf <11785335+leavesster@users.noreply.github.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "oocana-python-executor"
3
- version = "0.16.10"
3
+ version = "0.16.12"
4
4
  authors = [
5
5
  { name = "l1shen", email = "lishen1635@gmail.com" },
6
6
  { name = "yleaf", email = "11785335+leavesster@users.noreply.github.com" },
@@ -91,7 +91,6 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
91
91
  # 目前的 mqtt 库,在 subscribe 回调里 publish 消息会导致死锁无法工作,参考 https://github.com/eclipse/paho.mqtt.python/issues/527 或者 https://stackoverflow.com/a/36964192/4770006
92
92
  # 通过这种方式来绕过,所有需要 callback 后 publish message 的情况,都需要使用 future 类似方式来绕过。
93
93
  fs = queue.Queue()
94
- loop = asyncio.get_event_loop()
95
94
 
96
95
  def execute_block(message):
97
96
  if not_current_session(message):
@@ -108,9 +107,7 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
108
107
  job_set.add(job_id)
109
108
 
110
109
  nonlocal fs
111
- f = loop.create_future()
112
- fs.put(f)
113
- f.set_result(message)
110
+ fs.put(message)
114
111
 
115
112
  def execute_service_block(message):
116
113
  if not_current_session(message):
@@ -119,10 +116,7 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
119
116
  if not_current_job(message):
120
117
  return
121
118
 
122
- nonlocal fs
123
- f = loop.create_future()
124
- fs.put(f)
125
- f.set_result(message)
119
+ fs.put(message)
126
120
 
127
121
  def service_exit(message: ReportStatusPayload):
128
122
  service_hash = message.get("service_hash")
@@ -149,7 +143,7 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
149
143
 
150
144
  mainframe.subscribe(f"executor/{EXECUTOR_NAME}/run_block", execute_block)
151
145
  mainframe.subscribe(f"executor/{EXECUTOR_NAME}/run_service_block", execute_service_block)
152
- mainframe.subscribe('report', report_message)
146
+ mainframe.add_report_callback(report_message)
153
147
  mainframe.subscribe(exit_report_topic(), service_exit)
154
148
  mainframe.subscribe(status_report_topic(), service_status)
155
149
 
@@ -185,7 +179,6 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
185
179
  service_store[service_hash] = "running"
186
180
  run_in_new_thread(run)
187
181
 
188
- # FIXME: mqtt 不能在 subscribe 后立即 publish,需要修复。
189
182
  mainframe.subscribe(prepare_report_topic(params), lambda _: send_service_config(params, message))
190
183
 
191
184
  await process.wait()
@@ -203,24 +196,21 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
203
196
  mainframe.publish(run_action_topic(params), message)
204
197
 
205
198
  while True:
206
- await asyncio.sleep(0.1) # Avoid busy waiting
207
- if not fs.empty():
208
- f = fs.get()
209
- message = await f
210
- if message.get("service_executor") is not None:
211
- service_hash = message.get("service_hash")
212
- status = service_store.get(service_hash)
213
- if status is None:
214
- asyncio.create_task(spawn_service(message, service_hash))
215
- elif status == "running":
216
- run_service_block(message)
217
- elif status == "launching":
218
- logger.info(f"service {service_hash} is launching, set message back to fs to wait next time")
219
- fs.put(f)
220
- else:
221
- if not_current_session(message):
222
- continue
223
- run_block_in_new_thread(message, mainframe, session_dir=session_dir, tmp_dir=tmp_dir, package_name=package_name, pkg_dir=pkg_dir)
199
+ message = fs.get()
200
+ if message.get("service_executor") is not None:
201
+ service_hash = message.get("service_hash")
202
+ status = service_store.get(service_hash)
203
+ if status is None:
204
+ await spawn_service(message, service_hash)
205
+ elif status == "running":
206
+ run_service_block(message)
207
+ elif status == "launching":
208
+ logger.info(f"service {service_hash} is launching, set message back to fs to wait next time")
209
+ fs.put(message)
210
+ else:
211
+ if not_current_session(message):
212
+ continue
213
+ run_block_in_new_thread(message, mainframe, session_dir=session_dir, tmp_dir=tmp_dir, package_name=package_name, pkg_dir=pkg_dir)
224
214
 
225
215
  def run_block_in_new_thread(message, mainframe: Mainframe, session_dir: str, tmp_dir: str, package_name: str, pkg_dir: str):
226
216