From dac0ec5845d2b34d296ab7adbf98b48f9538852e Mon Sep 17 00:00:00 2001 From: Avinash Kumar Deepak Date: Fri, 13 Feb 2026 21:38:37 +0530 Subject: [PATCH 1/2] use context managers for file I/O - fixes #298 --- complete_rebase.sh | 5 ++ concore.egg-info/PKG-INFO | 106 ++++++++++++++++++++++++++ concore.egg-info/SOURCES.txt | 24 ++++++ concore.egg-info/dependency_links.txt | 1 + concore.egg-info/entry_points.txt | 2 + concore.egg-info/requires.txt | 9 +++ concore.egg-info/top_level.txt | 2 + setup_branch.ps1 | 8 ++ 8 files changed, 157 insertions(+) create mode 100644 complete_rebase.sh create mode 100644 concore.egg-info/PKG-INFO create mode 100644 concore.egg-info/SOURCES.txt create mode 100644 concore.egg-info/dependency_links.txt create mode 100644 concore.egg-info/entry_points.txt create mode 100644 concore.egg-info/requires.txt create mode 100644 concore.egg-info/top_level.txt create mode 100644 setup_branch.ps1 diff --git a/complete_rebase.sh b/complete_rebase.sh new file mode 100644 index 00000000..139801d8 --- /dev/null +++ b/complete_rebase.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd "D:\gsoc org\concore-project\concore" +git add requirements-dev.txt +git rebase --continue +git push origin add-concoredocker-tests --force diff --git a/concore.egg-info/PKG-INFO b/concore.egg-info/PKG-INFO new file mode 100644 index 00000000..7924d4eb --- /dev/null +++ b/concore.egg-info/PKG-INFO @@ -0,0 +1,106 @@ +Metadata-Version: 2.4 +Name: concore +Version: 1.0.0 +Summary: Concore workflow management CLI +Home-page: https://github.com/ControlCore-Project/concore +Author: ControlCore Project +License: MIT +Requires-Python: >=3.9 +Description-Content-Type: text/markdown +License-File: LICENSE +Requires-Dist: click>=8.0.0 +Requires-Dist: rich>=10.0.0 +Requires-Dist: beautifulsoup4>=4.9.0 +Requires-Dist: lxml>=4.6.0 +Requires-Dist: psutil>=5.8.0 +Provides-Extra: dev +Requires-Dist: pytest>=6.0.0; extra == "dev" +Requires-Dist: pytest-cov>=2.10.0; extra == "dev" +Dynamic: author +Dynamic: home-page +Dynamic: license-file +Dynamic: requires-python + +# CONTROL-CORE: Integrated Development Environment for Closed-loop Neuromodulation Control Systems. + +[CONTROL-CORE](https://github.com/ControlCore-Project/) is a design and simulation framework, functioning as a visual Integrated Development Environment (IDE) for Closed-loop Neuromodulation Control Systems. At its center is _concore_, a lightweight protocol to simulate neuromodulation control systems. This repository consists of the implementation of _concore_ protocol and sample (demo and neuromodulation control systems) studies. In addition to its default standard Python implementation, _concore_ also supports developing studies in Matlab/Octave, Verilog, and C++. _concore_ also aims to support more language programs in the future. + +# The CONTROL-CORE Framework + +The CONTROL-CORE framework consists of the below projects. + +* _concore_: The CONTROL-CORE protocol, known as _concore_, allows modular simulation of controller and PM nodes to run on different operating systems, computing platforms, and programming languages. [This repository](https://github.com/ControlCore-Project/concore/) consists of _concore_ source code. The _concore_ documentation can be found [here](https://control-core.readthedocs.io/en/latest/index.html). A _concore_ study can be developed from programs written in different languages. That means, _concore_ facilitates a seamless communication across codes developed in different languages that it supports, through its simple file-based data sharing between the programs. + +* _concore_ Editor: This is the front-end for CONTROL-CORE. We forked [DHGWorkflow](https://github.com/ControlCore-Project/DHGWorkflow), a sibling project we developed, and extend it as the _concore_ Editor. + +* _Mediator_: The [Mediator](https://github.com/ControlCore-Project/mediator) allows the CONTROL-CORE studies to be distributed and run, rather than having all the programs that construct a study to be run just from a centralized location. + +* _concore-lite_: The [_concore-lite_](https://github.com/ControlCore-Project/concore-lite) repository consists of a simple example version of a _concore_ study. Please check out and run this, if you like to learn the _concore_ protocol without having to clone this large _concore_ repository. + +* documentation: The [source code repository](https://github.com/ControlCore-Project/documentation) of the ReadTheDocs documentation of CONTROL-CORE. + + +# The _concore_ Protocol + +_concore_ enables composing studies from programs developed in different languages. Currently supported languages are, Python, Matlab/Octave, Verilog, and C++. The studies are designed through the visual _concore_ Editor (DHGWorkflow) and interpreted into _concore_ through its parser. Neural control systems consist of loops (dicycles). Therefore, they cannot be represented by classic workflow standards (such as CWL or WDL). Therefore, _concore_ addresses a significant research gap to model closed-loop neuromodulation control systems. The _concore_ protocol shares data between the programs through file sharing, with no centralized entity (a broker or an orchestrator) to arbitrate communications between the programs. (In the distributed executions, the CONTROL-CORE Mediator enables connecting the disjoint pieces of the study through REST APIs). + + +# Installation and Getting Started Guide + +Please follow the [ReadTheDocs](https://control-core.readthedocs.io/en/latest/index.html) documentation and the [_concore-lite_](https://github.com/ControlCore-Project/concore-lite) repository to get started quick. + +Installation instructions for concore can be found [here](https://control-core.readthedocs.io/en/latest/installation.html). Usage instructions can be found [here](https://control-core.readthedocs.io/en/latest/usage.html). + +## Command-Line Interface (CLI) + +_concore_ now includes a command-line interface for easier workflow management. Install it with: + +```bash +pip install -e . +``` + +Quick start with the CLI: + +```bash +# Create a new project +concore init my-project + +# Validate your workflow +concore validate workflow.graphml + +# Run your workflow +concore run workflow.graphml --auto-build + +# Monitor running processes +concore status + +# Stop all processes +concore stop +``` + +For detailed CLI documentation, see [concore_cli/README.md](concore_cli/README.md). + +For a detailed and more scientific documentation, please read our extensive [open-access research paper on CONTROL-CORE](https://doi.org/10.1109/ACCESS.2022.3161471). This paper has a complete discussion on the CONTROL-CORE architecture and deployment, together with the commands to execute the studies in different programming languages and programming environments (Ubuntu, Windows, MacOS, Docker, and distributed execution). + + +# The _concore_ Repository + +_concore_ contains programs (such as physiological models or more commonly called "PMs" and controllers) and studies (i.e., graphml files that represents the studies as workflows). The _wrappers_ enable seamlessly extending a study into a distributed one with the CONTROL-CORE Mediator. + +_concore_ repository consists of several scripts at its root level. The demo folder consists of several sample programs and studies, mostly toy examples to learn the protocol. The ratc folder consists of the programs and studies of the rat cardiac experiments we developed with _concore_. + +If you have a bug to report in one of the CONTROL-CORE projects, please report it through relevant Issue Tracker. Similarly, please feel free to contribute your studies and code enhancements using pull requests. Questions and discussions can be made through the relevant Discussions forum. + +The _concore_ Issues can be reported [here](https://github.com/ControlCore-Project/concore/issues). + +The _concore_ discussion forum can be found [here](https://github.com/ControlCore-Project/concore/discussions). + +Please make sure to send your _concore_ pull requests to the [dev branch](https://github.com/ControlCore-Project/concore/tree/dev). + + +# Citing _concore_ + +If you use _concore_ in your research, please cite the below papers: + +* Kathiravelu, P., Arnold, M., Vijay, S., Jagwani, R., Goyal, P., Goel, A.K., Li, N., Horn, C., Pan, T., Kothare, M. V., and Mahmoudi, B. **Distributed Executions with CONTROL-CORE Integrated Development Environment (IDE) for Closed-loop Neuromodulation Control Systems.** In Cluster Computing – The Journal of Networks Software Tools and Applications (CLUSTER). May 2025. Accepted. Springer. +* Kathiravelu, P., Arnold, M., Fleischer, J., Yao, Y., Awasthi, S., Goel, A. K., Branen, A., Sarikhani, P., Kumar, G., Kothare, M. V., and Mahmoudi, B. **CONTROL-CORE: A Framework for Simulation and Design of Closed-Loop Peripheral Neuromodulation Control Systems**. In IEEE Access. March 2022. https://doi.org/10.1109/ACCESS.2022.3161471 diff --git a/concore.egg-info/SOURCES.txt b/concore.egg-info/SOURCES.txt new file mode 100644 index 00000000..99020ca8 --- /dev/null +++ b/concore.egg-info/SOURCES.txt @@ -0,0 +1,24 @@ +LICENSE +README.md +mkconcore.py +pyproject.toml +setup.py +concore.egg-info/PKG-INFO +concore.egg-info/SOURCES.txt +concore.egg-info/dependency_links.txt +concore.egg-info/entry_points.txt +concore.egg-info/requires.txt +concore.egg-info/top_level.txt +concore_cli/__init__.py +concore_cli/cli.py +concore_cli/commands/__init__.py +concore_cli/commands/init.py +concore_cli/commands/inspect.py +concore_cli/commands/run.py +concore_cli/commands/status.py +concore_cli/commands/stop.py +concore_cli/commands/validate.py +tests/test_cli.py +tests/test_concore.py +tests/test_concoredocker.py +tests/test_graph.py \ No newline at end of file diff --git a/concore.egg-info/dependency_links.txt b/concore.egg-info/dependency_links.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/concore.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/concore.egg-info/entry_points.txt b/concore.egg-info/entry_points.txt new file mode 100644 index 00000000..a71a8db6 --- /dev/null +++ b/concore.egg-info/entry_points.txt @@ -0,0 +1,2 @@ +[console_scripts] +concore = concore_cli.cli:cli diff --git a/concore.egg-info/requires.txt b/concore.egg-info/requires.txt new file mode 100644 index 00000000..3895f3f9 --- /dev/null +++ b/concore.egg-info/requires.txt @@ -0,0 +1,9 @@ +click>=8.0.0 +rich>=10.0.0 +beautifulsoup4>=4.9.0 +lxml>=4.6.0 +psutil>=5.8.0 + +[dev] +pytest>=6.0.0 +pytest-cov>=2.10.0 diff --git a/concore.egg-info/top_level.txt b/concore.egg-info/top_level.txt new file mode 100644 index 00000000..3c4fe8d8 --- /dev/null +++ b/concore.egg-info/top_level.txt @@ -0,0 +1,2 @@ +concore_cli +mkconcore diff --git a/setup_branch.ps1 b/setup_branch.ps1 new file mode 100644 index 00000000..05b36bfc --- /dev/null +++ b/setup_branch.ps1 @@ -0,0 +1,8 @@ +cd "D:\gsoc org\concore-project\concore" +git config core.editor "notepad" +git fetch upstream +git checkout dev +git reset --hard upstream/dev +git branch -D refactor-file-io-v2 2>$null +git checkout -b refactor-file-io-v2 +Write-Host "Branch ready!" From e653cd8b4f48146547ff110685c770294dc696f7 Mon Sep 17 00:00:00 2001 From: Avinash Kumar Deepak Date: Fri, 13 Feb 2026 21:41:33 +0530 Subject: [PATCH 2/2] use context managers for file I/O --- complete_rebase.sh | 5 -- concore.egg-info/PKG-INFO | 106 -------------------------- concore.egg-info/SOURCES.txt | 24 ------ concore.egg-info/dependency_links.txt | 1 - concore.egg-info/entry_points.txt | 2 - concore.egg-info/requires.txt | 9 --- concore.egg-info/top_level.txt | 2 - setup_branch.ps1 | 8 -- tools/cwrap.py | 56 +++++++++----- 9 files changed, 35 insertions(+), 178 deletions(-) delete mode 100644 complete_rebase.sh delete mode 100644 concore.egg-info/PKG-INFO delete mode 100644 concore.egg-info/SOURCES.txt delete mode 100644 concore.egg-info/dependency_links.txt delete mode 100644 concore.egg-info/entry_points.txt delete mode 100644 concore.egg-info/requires.txt delete mode 100644 concore.egg-info/top_level.txt delete mode 100644 setup_branch.ps1 diff --git a/complete_rebase.sh b/complete_rebase.sh deleted file mode 100644 index 139801d8..00000000 --- a/complete_rebase.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -cd "D:\gsoc org\concore-project\concore" -git add requirements-dev.txt -git rebase --continue -git push origin add-concoredocker-tests --force diff --git a/concore.egg-info/PKG-INFO b/concore.egg-info/PKG-INFO deleted file mode 100644 index 7924d4eb..00000000 --- a/concore.egg-info/PKG-INFO +++ /dev/null @@ -1,106 +0,0 @@ -Metadata-Version: 2.4 -Name: concore -Version: 1.0.0 -Summary: Concore workflow management CLI -Home-page: https://github.com/ControlCore-Project/concore -Author: ControlCore Project -License: MIT -Requires-Python: >=3.9 -Description-Content-Type: text/markdown -License-File: LICENSE -Requires-Dist: click>=8.0.0 -Requires-Dist: rich>=10.0.0 -Requires-Dist: beautifulsoup4>=4.9.0 -Requires-Dist: lxml>=4.6.0 -Requires-Dist: psutil>=5.8.0 -Provides-Extra: dev -Requires-Dist: pytest>=6.0.0; extra == "dev" -Requires-Dist: pytest-cov>=2.10.0; extra == "dev" -Dynamic: author -Dynamic: home-page -Dynamic: license-file -Dynamic: requires-python - -# CONTROL-CORE: Integrated Development Environment for Closed-loop Neuromodulation Control Systems. - -[CONTROL-CORE](https://github.com/ControlCore-Project/) is a design and simulation framework, functioning as a visual Integrated Development Environment (IDE) for Closed-loop Neuromodulation Control Systems. At its center is _concore_, a lightweight protocol to simulate neuromodulation control systems. This repository consists of the implementation of _concore_ protocol and sample (demo and neuromodulation control systems) studies. In addition to its default standard Python implementation, _concore_ also supports developing studies in Matlab/Octave, Verilog, and C++. _concore_ also aims to support more language programs in the future. - -# The CONTROL-CORE Framework - -The CONTROL-CORE framework consists of the below projects. - -* _concore_: The CONTROL-CORE protocol, known as _concore_, allows modular simulation of controller and PM nodes to run on different operating systems, computing platforms, and programming languages. [This repository](https://github.com/ControlCore-Project/concore/) consists of _concore_ source code. The _concore_ documentation can be found [here](https://control-core.readthedocs.io/en/latest/index.html). A _concore_ study can be developed from programs written in different languages. That means, _concore_ facilitates a seamless communication across codes developed in different languages that it supports, through its simple file-based data sharing between the programs. - -* _concore_ Editor: This is the front-end for CONTROL-CORE. We forked [DHGWorkflow](https://github.com/ControlCore-Project/DHGWorkflow), a sibling project we developed, and extend it as the _concore_ Editor. - -* _Mediator_: The [Mediator](https://github.com/ControlCore-Project/mediator) allows the CONTROL-CORE studies to be distributed and run, rather than having all the programs that construct a study to be run just from a centralized location. - -* _concore-lite_: The [_concore-lite_](https://github.com/ControlCore-Project/concore-lite) repository consists of a simple example version of a _concore_ study. Please check out and run this, if you like to learn the _concore_ protocol without having to clone this large _concore_ repository. - -* documentation: The [source code repository](https://github.com/ControlCore-Project/documentation) of the ReadTheDocs documentation of CONTROL-CORE. - - -# The _concore_ Protocol - -_concore_ enables composing studies from programs developed in different languages. Currently supported languages are, Python, Matlab/Octave, Verilog, and C++. The studies are designed through the visual _concore_ Editor (DHGWorkflow) and interpreted into _concore_ through its parser. Neural control systems consist of loops (dicycles). Therefore, they cannot be represented by classic workflow standards (such as CWL or WDL). Therefore, _concore_ addresses a significant research gap to model closed-loop neuromodulation control systems. The _concore_ protocol shares data between the programs through file sharing, with no centralized entity (a broker or an orchestrator) to arbitrate communications between the programs. (In the distributed executions, the CONTROL-CORE Mediator enables connecting the disjoint pieces of the study through REST APIs). - - -# Installation and Getting Started Guide - -Please follow the [ReadTheDocs](https://control-core.readthedocs.io/en/latest/index.html) documentation and the [_concore-lite_](https://github.com/ControlCore-Project/concore-lite) repository to get started quick. - -Installation instructions for concore can be found [here](https://control-core.readthedocs.io/en/latest/installation.html). Usage instructions can be found [here](https://control-core.readthedocs.io/en/latest/usage.html). - -## Command-Line Interface (CLI) - -_concore_ now includes a command-line interface for easier workflow management. Install it with: - -```bash -pip install -e . -``` - -Quick start with the CLI: - -```bash -# Create a new project -concore init my-project - -# Validate your workflow -concore validate workflow.graphml - -# Run your workflow -concore run workflow.graphml --auto-build - -# Monitor running processes -concore status - -# Stop all processes -concore stop -``` - -For detailed CLI documentation, see [concore_cli/README.md](concore_cli/README.md). - -For a detailed and more scientific documentation, please read our extensive [open-access research paper on CONTROL-CORE](https://doi.org/10.1109/ACCESS.2022.3161471). This paper has a complete discussion on the CONTROL-CORE architecture and deployment, together with the commands to execute the studies in different programming languages and programming environments (Ubuntu, Windows, MacOS, Docker, and distributed execution). - - -# The _concore_ Repository - -_concore_ contains programs (such as physiological models or more commonly called "PMs" and controllers) and studies (i.e., graphml files that represents the studies as workflows). The _wrappers_ enable seamlessly extending a study into a distributed one with the CONTROL-CORE Mediator. - -_concore_ repository consists of several scripts at its root level. The demo folder consists of several sample programs and studies, mostly toy examples to learn the protocol. The ratc folder consists of the programs and studies of the rat cardiac experiments we developed with _concore_. - -If you have a bug to report in one of the CONTROL-CORE projects, please report it through relevant Issue Tracker. Similarly, please feel free to contribute your studies and code enhancements using pull requests. Questions and discussions can be made through the relevant Discussions forum. - -The _concore_ Issues can be reported [here](https://github.com/ControlCore-Project/concore/issues). - -The _concore_ discussion forum can be found [here](https://github.com/ControlCore-Project/concore/discussions). - -Please make sure to send your _concore_ pull requests to the [dev branch](https://github.com/ControlCore-Project/concore/tree/dev). - - -# Citing _concore_ - -If you use _concore_ in your research, please cite the below papers: - -* Kathiravelu, P., Arnold, M., Vijay, S., Jagwani, R., Goyal, P., Goel, A.K., Li, N., Horn, C., Pan, T., Kothare, M. V., and Mahmoudi, B. **Distributed Executions with CONTROL-CORE Integrated Development Environment (IDE) for Closed-loop Neuromodulation Control Systems.** In Cluster Computing – The Journal of Networks Software Tools and Applications (CLUSTER). May 2025. Accepted. Springer. -* Kathiravelu, P., Arnold, M., Fleischer, J., Yao, Y., Awasthi, S., Goel, A. K., Branen, A., Sarikhani, P., Kumar, G., Kothare, M. V., and Mahmoudi, B. **CONTROL-CORE: A Framework for Simulation and Design of Closed-Loop Peripheral Neuromodulation Control Systems**. In IEEE Access. March 2022. https://doi.org/10.1109/ACCESS.2022.3161471 diff --git a/concore.egg-info/SOURCES.txt b/concore.egg-info/SOURCES.txt deleted file mode 100644 index 99020ca8..00000000 --- a/concore.egg-info/SOURCES.txt +++ /dev/null @@ -1,24 +0,0 @@ -LICENSE -README.md -mkconcore.py -pyproject.toml -setup.py -concore.egg-info/PKG-INFO -concore.egg-info/SOURCES.txt -concore.egg-info/dependency_links.txt -concore.egg-info/entry_points.txt -concore.egg-info/requires.txt -concore.egg-info/top_level.txt -concore_cli/__init__.py -concore_cli/cli.py -concore_cli/commands/__init__.py -concore_cli/commands/init.py -concore_cli/commands/inspect.py -concore_cli/commands/run.py -concore_cli/commands/status.py -concore_cli/commands/stop.py -concore_cli/commands/validate.py -tests/test_cli.py -tests/test_concore.py -tests/test_concoredocker.py -tests/test_graph.py \ No newline at end of file diff --git a/concore.egg-info/dependency_links.txt b/concore.egg-info/dependency_links.txt deleted file mode 100644 index 8b137891..00000000 --- a/concore.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/concore.egg-info/entry_points.txt b/concore.egg-info/entry_points.txt deleted file mode 100644 index a71a8db6..00000000 --- a/concore.egg-info/entry_points.txt +++ /dev/null @@ -1,2 +0,0 @@ -[console_scripts] -concore = concore_cli.cli:cli diff --git a/concore.egg-info/requires.txt b/concore.egg-info/requires.txt deleted file mode 100644 index 3895f3f9..00000000 --- a/concore.egg-info/requires.txt +++ /dev/null @@ -1,9 +0,0 @@ -click>=8.0.0 -rich>=10.0.0 -beautifulsoup4>=4.9.0 -lxml>=4.6.0 -psutil>=5.8.0 - -[dev] -pytest>=6.0.0 -pytest-cov>=2.10.0 diff --git a/concore.egg-info/top_level.txt b/concore.egg-info/top_level.txt deleted file mode 100644 index 3c4fe8d8..00000000 --- a/concore.egg-info/top_level.txt +++ /dev/null @@ -1,2 +0,0 @@ -concore_cli -mkconcore diff --git a/setup_branch.ps1 b/setup_branch.ps1 deleted file mode 100644 index 05b36bfc..00000000 --- a/setup_branch.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -cd "D:\gsoc org\concore-project\concore" -git config core.editor "notepad" -git fetch upstream -git checkout dev -git reset --hard upstream/dev -git branch -D refactor-file-io-v2 2>$null -git checkout -b refactor-file-io-v2 -Write-Host "Branch ready!" diff --git a/tools/cwrap.py b/tools/cwrap.py index 912423e7..d19caee3 100644 --- a/tools/cwrap.py +++ b/tools/cwrap.py @@ -11,51 +11,63 @@ concore.delay = 0.02 try: - apikey=open(concore.inpath+'1/concore.apikey',newline=None).readline().rstrip() + with open(concore.inpath+'1/concore.apikey',newline=None) as f: + apikey=f.readline().rstrip() except (OSError, IOError): try: #perhaps this should be removed for security - apikey=open('./concore.apikey',newline=None).readline().rstrip() + with open('./concore.apikey',newline=None) as f: + apikey=f.readline().rstrip() except (OSError, IOError): apikey = '' try: - yuyu=open(concore.inpath+'1/concore.yuyu',newline=None).readline().rstrip() + with open(concore.inpath+'1/concore.yuyu',newline=None) as f: + yuyu=f.readline().rstrip() except (OSError, IOError): try: - yuyu=open('./concore.yuyu',newline=None).readline().rstrip() + with open('./concore.yuyu',newline=None) as f: + yuyu=f.readline().rstrip() except (OSError, IOError): yuyu = 'yuyu' try: - name1=open(concore.inpath+'1/concore.name1',newline=None).readline().rstrip() + with open(concore.inpath+'1/concore.name1',newline=None) as f: + name1=f.readline().rstrip() except (OSError, IOError): try: - name1=open('./concore.name1',newline=None).readline().rstrip() + with open('./concore.name1',newline=None) as f: + name1=f.readline().rstrip() except (OSError, IOError): name1 = 'u' try: - name2=open(concore.inpath+'1/concore.name2',newline=None).readline().rstrip() + with open(concore.inpath+'1/concore.name2',newline=None) as f: + name2=f.readline().rstrip() except (OSError, IOError): try: - name2=open('./concore.name2',newline=None).readline().rstrip() + with open('./concore.name2',newline=None) as f: + name2=f.readline().rstrip() except (OSError, IOError): name2 = 'ym' try: - init_simtime_u = open(concore.inpath+'1/concore.init1',newline=None).readline().rstrip() + with open(concore.inpath+'1/concore.init1',newline=None) as f: + init_simtime_u = f.readline().rstrip() except (OSError, IOError): try: - init_simtime_u = open('./concore.init1',newline=None).readline().rstrip() + with open('./concore.init1',newline=None) as f: + init_simtime_u = f.readline().rstrip() except (OSError, IOError): init_simtime_u = "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]" try: - init_simtime_ym = open(concore.inpath+'1/concore.init2',newline=None).readline().rstrip() + with open(concore.inpath+'1/concore.init2',newline=None) as f: + init_simtime_ym = f.readline().rstrip() except (OSError, IOError): try: - init_simtime_ym = open('./concore.init2',newline=None).readline().rstrip() + with open('./concore.init2',newline=None) as f: + init_simtime_ym = f.readline().rstrip() except (OSError, IOError): init_simtime_ym = "[0.0, 0.0, 0.0]" @@ -82,10 +94,11 @@ logging.debug("CW outer loop") while concore.unchanged(): u = concore.read(1,name1,init_simtime_u) - f = {'file1': open(concore.inpath+'1/'+name1, 'rb')} - logging.debug(f"CW: before post u={u}") - logging.debug(f'http://www.controlcore.org/pm/{yuyu}{apikey}&fetch={name2}') - r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max) + with open(concore.inpath+'1/'+name1, 'rb') as f1: + f = {'file1': f1} + logging.debug(f"CW: before post u={u}") + logging.debug(f'http://www.controlcore.org/pm/{yuyu}{apikey}&fetch={name2}') + r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max) if r.status_code!=200: logging.error(f"bad POST request {r.status_code}") quit() @@ -101,11 +114,12 @@ while oldt==t or len(r.content)==0: time.sleep(concore.delay) logging.debug(f"CW waiting status={r.status_code} content={r.content.decode('utf-8')} t={t}") - f = {'file1': open(concore.inpath+'1/'+name1, 'rb')} - try: - r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max) - except Exception: - logging.error("CW: bad request") + with open(concore.inpath+'1/'+name1, 'rb') as f1: + f = {'file1': f1} + try: + r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max) + except Exception: + logging.error("CW: bad request") timeout_count += 1 if r.status_code!=200 or time.perf_counter()-t1 > 1.1*timeout_max: #timeout_count>100: logging.error(f"timeout or bad POST request {r.status_code}")