Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 21633f74 authored by Franck Thollard's avatar Franck Thollard
Browse files

providing a 'nicer' format for logging. Handling ret code in suprocess example

parent 4cb98a81
......@@ -661,28 +661,28 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"command failed with return code 1\n"
]
}
],
"source": [
"import subprocess\n",
"def call_bash(commands):\n",
" return subprocess.call(['/bin/bash', '-c', commands])\n",
"call_bash(\"\"\"\n",
"echo Hello\n",
"grep toto -r\n",
"\"\"\")"
"ret = call_bash(\"\"\"\n",
"echo Hello; cat /tmp/jfdkfjdk\n",
"\"\"\")\n",
"if ret == 0:\n",
" print(\"command succeed\")\n",
"else:\n",
" print(f\"command failed with return code {ret}\")"
]
},
{
......@@ -713,14 +713,14 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Would you like to have a \"beer\"?\n"
"2019-01-29 21:33:57,439 - root - INFO - Would you like to have a \"beer\"?\n"
]
}
],
......@@ -728,8 +728,9 @@
"import logging\n",
"log_level = logging.INFO # to get information messages\n",
"# log_level = logging.WARNING # no information messages\n",
"logging.basicConfig(format='%(message)s',\n",
" level=log_level)\n",
"logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n",
" level=logging.INFO)\n",
" level=log_level)\n",
"\n",
"thing = 'beer'\n",
"logging.info('Would you like to have a \"%s\"?', thing)"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment