Use $SGE_TASK_ID in the python script
This thread told me to use $SGE_TASK_ID to generate random integer https://salilab.org/archives/modeller_usage/2020/msg00077.html
I tried: random_integer = int(-1*str($SGE_TASK_ID)[-4:]) # so that the number is within the range of (-50000, -2)
But I was told the $ sign is invalid: random_integer = int(-1*str($SGE_TASK_ID)[-4:]) ^ SyntaxError: invalid syntax
So is that possible to use the job ID (e.g. 7172646) as an variable in the python environment? Thank you!
On 5/13/21 8:05 AM, ZHANG Cheng wrote: > random_integer = int(-1*str($SGE_TASK_ID)[-4:]) > ^ > SyntaxError: invalid syntax > > So is that possible to use the job ID (e.g. 7172646) as an variable in > the python environment? Thank you!
A simple Google search tells you the answer; here's one hit: https://www.askpython.com/python/environment-variables-in-python
In your case, you want to use os.environ['SGE_TASK_ID'] rather than $SGE_TASK_ID.
Ben Webb, Modeller Caretaker
I tried this,
task_id = os.environ["SGE_TASK_ID"] print(task_id)
But I got "undefined" printed out.
------------------ Original ------------------ From: "Modeller Caretaker" <modeller-care@salilab.org>; Date: Fri, May 14, 2021 00:15 AM To: "ZHANG Cheng"<272699575@qq.com>;"modeller_usage"<modeller_usage@salilab.org>;
Subject: Re: [modeller_usage] Use $SGE_TASK_ID in the python script
On 5/13/21 8:05 AM, ZHANG Cheng wrote: > random_integer = int(-1*str($SGE_TASK_ID)[-4:]) > ^ > SyntaxError: invalid syntax > > So is that possible to use the job ID (e.g. 7172646) as an variable in > the python environment? Thank you!
A simple Google search tells you the answer; here's one hit: https://www.askpython.com/python/environment-variables-in-python
In your case, you want to use os.environ['SGE_TASK_ID'] rather than $SGE_TASK_ID.
Ben Webb, Modeller Caretaker
Hi, I got the solution, it should be
task_id = os.environ["JOB_ID"]
------------------ Original ------------------ From: "ZHANG Cheng" <272699575@qq.com>; Date: Fri, May 14, 2021 00:20 AM To: "Modeller Caretaker"<modeller-care@salilab.org>;"modeller_usage"<modeller_usage@salilab.org>;
Subject: Re: [modeller_usage] Use $SGE_TASK_ID in the python script
I tried this,
task_id = os.environ["SGE_TASK_ID"] print(task_id)
But I got "undefined" printed out.
------------------ Original ------------------ From: "Modeller Caretaker" <modeller-care@salilab.org>; Date: Fri, May 14, 2021 00:15 AM To: "ZHANG Cheng"<272699575@qq.com>;"modeller_usage"<modeller_usage@salilab.org>;
Subject: Re: [modeller_usage] Use $SGE_TASK_ID in the python script
On 5/13/21 8:05 AM, ZHANG Cheng wrote: > random_integer = int(-1*str($SGE_TASK_ID)[-4:]) > ^ > SyntaxError: invalid syntax > > So is that possible to use the job ID (e.g. 7172646) as an variable in > the python environment? Thank you!
A simple Google search tells you the answer; here's one hit: https://www.askpython.com/python/environment-variables-in-python
In your case, you want to use os.environ['SGE_TASK_ID'] rather than $SGE_TASK_ID.
Ben Webb, Modeller Caretaker
participants (2)
-
Modeller Caretaker
-
ZHANG Cheng