Hi I've installed gridengine on a 4-node cluster using the following command:
sudo apt-get install gridengine-client gridengine-qmon gridengine-exec gridengine-master
sudo apt-get install gridengine-exec gridengine-client
And it returned:
SGE_ROOT: /var/lib/gridengine
SGE_CELL: bms
I've therefore done all the necessary step to configure the gridengine and it works.
However I want to run my job using python drmaa library and I've installed on the master node:
sudo apt-get install libdrmaa-dev
pip install drmaa
So if i query the system with following script:
#!/usr/bin/env python
import drmaa
def main():
"""Query the system."""
s = drmaa.Session()
s.initialize()
print 'A DRMAA object was created'
print 'Supported contact strings: ' + s.contact
print 'Supported DRM systems: ' + str(s.drmsInfo)
print 'Supported DRMAA implementations: ' + str(s.drmaaImplementation)
print 'Version ' + str(s.version)
print 'Exiting'
s.exit()
if __name__=='__main__':
main()
It returns:
A DRMAA object was created
Supported contact strings: session=NGS-1.9217.1679116461
Supported DRM systems: GE 6.2u5
Supported DRMAA implementations: GE 6.2u5
Version 1.0
Exiting
But if I try to run a job with the script suggested by the link:
http://code.google.com/p/drmaa-python/wiki/Tutorial#Running_a_Job
It returns
drmaa.errors.NoActiveSessionException: code 5: No active session
Could anyone help me?
What's wrong.
The drmaa library looks like is able to communicate with gridengine but it cannot run a job.
Why it raise this error?
I would really appreciate any kind of help.
you will find that the example of running job using DRMAA does not initialize the session so just add s.initialize() after creating new session s = drmaa.Session() as following:
#!/usr/bin/env python
import drmaa
import os
def main():
"""Submit a job.
Note, need file called sleeper.sh in current directory.
"""
s = drmaa.Session()
s.initialize()
print 'Creating job template'
jt = s.createJobTemplate()
jt.remoteCommand = os.getcwd() + '/sleeper.sh'
jt.args = ['42','Simon says:']
jt.joinFiles=True
jobid = s.runJob(jt)
print 'Your job has been submitted with id ' + jobid
print 'Cleaning up'
s.deleteJobTemplate(jt)
s.exit()
if __name__=='__main__':
main()
Related
I have actualy python script running on background, you can see how it's displayed when i use command "ps -aux" :
root 405 0.0 2.6 34052 25328 ? S 09:52 0:04 python3 -u /opt/flask_server/downlink_server/downlink_manager.py
i want to check if this script are running from another python script, so i try to us psutil module, but it just detect that python3 are running but not my script precisely !
there is my python script :
import os
import psutil
import time
import logging
import sys
for process in psutil.process_iter():
if process.cmdline() == ['python3', '/opt/flask_server/downlink_server/downlink_manager.py']:
print('Process found: exiting.')
It's look like simple, but trust me, i already try other function proposed on another topic, like this :
def find_procs_by_name(name):
"Return a list of processes matching 'name'."
ls = []
for p in psutil.process_iter(attrs=["name", "exe", "cmdline"]):
if name == p.info['name'] or \
p.info['exe'] and os.path.basename(p.info['exe']) == name or \
p.info['cmdline'] and p.info['cmdline'][0] == name:
ls.append(p)
return ls
ls = find_procs_by_name("downlink_manager.py")
But this function didn't fin my script, it's work, when i search python3 but not the name of the script.
Of course i try to put all the path of the script but nothing, can you please hepl me ?
I resolve the issue with this modification :
import psutil
proc_iter = psutil.process_iter(attrs=["pid", "name", "cmdline"])
process = any("/opt/flask_server/downlink_server/downlink_manager.py" in p.info["cmdline"] for p in proc_iter)
print(process)
I've been working on getting Google Assistant working on my Raspberry Pi 3.
It is working but I'm having problems getting this specific step to work:
https://developers.google.com/assistant/sdk/guides/library/python/extend/handle-device-commands
This step covers sending an on/off command to the Pi to turn a LED bulb on or off.
I have confirmed the Bread board and LED is setup correctly because I can turn the LED on or off via a python script.
However, after following the steps in that page and trying to run the following command "python hotword.py --device_model_id my-model"
(which is actually: python hotword.py --device_model_id assistantraspi-1d671-pigooglev2-8n98u3)
I get the following error:
ImportError: No module named pathlib2
I am including a copy of that file (hotword.py)
#!/usr/bin/env python
# Copyright (C) 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import argparse
import json
import os.path
import pathlib2 as pathlib
import RPi.GPIO as GPIO
import google.oauth2.credentials
from google.assistant.library import Assistant
from google.assistant.library.event import EventType
from google.assistant.library.file_helpers import existing_file
from google.assistant.library.device_helpers import register_device
try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError
WARNING_NOT_REGISTERED = """
This device is not registered. This means you will not be able to use
Device Actions or see your device in Assistant Settings. In order to
register this device follow instructions at:
https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device
"""
def process_event(event):
"""Pretty prints events.
Prints all events that occur with two spaces between each new
conversation and a single space between turns of a conversation.
Args:
event(event.Event): The current event to process.
"""
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
print()
print(event)
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
event.args and not event.args['with_follow_on_turn']):
print()
if event.type == EventType.ON_DEVICE_ACTION:
for command, params in event.actions:
print('Do command', command, 'with params', str(params))
if command == "action.devices.commands.OnOff":
if params['on']:
print('Turning the LED on.')
GPIO.output(25, 1)
else:
print('Turning the LED off.')
GPIO.output(25, 0)
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--device-model-id', '--device_model_id', type=str,
metavar='DEVICE_MODEL_ID', required=False,
help='the device model ID registered with Google')
parser.add_argument('--project-id', '--project_id', type=str,
metavar='PROJECT_ID', required=False,
help='the project ID used to register this device')
parser.add_argument('--device-config', type=str,
metavar='DEVICE_CONFIG_FILE',
default=os.path.join(
os.path.expanduser('~/.config'),
'googlesamples-assistant',
'device_config_library.json'
),
help='path to store and read device configuration')
parser.add_argument('--credentials', type=existing_file,
metavar='OAUTH2_CREDENTIALS_FILE',
default=os.path.join(
os.path.expanduser('~/.config'),
'google-oauthlib-tool',
'credentials.json'
),
help='path to store and read OAuth2 credentials')
parser.add_argument('-v', '--version', action='version',
version='%(prog)s ' + Assistant.__version_str__())
args = parser.parse_args()
with open(args.credentials, 'r') as f:
credentials = google.oauth2.credentials.Credentials(token=None,
**json.load(f))
device_model_id = None
last_device_id = None
try:
with open(args.device_config) as f:
device_config = json.load(f)
device_model_id = device_config['model_id']
last_device_id = device_config.get('last_device_id', None)
except FileNotFoundError:
pass
if not args.device_model_id and not device_model_id:
raise Exception('Missing --device-model-id option')
# Re-register if "device_model_id" is given by the user and it differs
# from what we previously registered with.
should_register = (
args.device_model_id and args.device_model_id != device_model_id)
device_model_id = args.device_model_id or device_model_id
with Assistant(credentials, device_model_id) as assistant:
events = assistant.start()
device_id = assistant.device_id
print('device_model_id:', device_model_id)
print('device_id:', device_id + '\n')
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT, initial=GPIO.LOW)
# Re-register if "device_id" is different from the last "device_id":
if should_register or (device_id != last_device_id):
if args.project_id:
register_device(args.project_id, credentials,
device_model_id, device_id)
pathlib.Path(os.path.dirname(args.device_config)).mkdir(
exist_ok=True)
with open(args.device_config, 'w') as f:
json.dump({
'last_device_id': device_id,
'model_id': device_model_id,
}, f)
else:
print(WARNING_NOT_REGISTERED)
for event in events:
process_event(event)
if __name__ == '__main__':
main()
Have you tried installing pathlib2 with pip or pip3? Please try
pip install pathlib2
if you're using Python2, and
pip3 install pathlib2
if you're using Python3. However, If pip is not found, then try installing it with
apt-get install python-pip python3-pip
Thanks for the suggestions. Turns out the solution was pretty simple.
The solution is two fold:
1: I have to run the following command first:
source env/bin/activate
Then I could run the python script without getting an error
(env) pi#raspberrypi:~/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library $ python hotword.py --device_model_id assistantraspi-1d671-pigooglev2-8n98u3
As I progressed through the articles, the source becomes deactivated per se and returns to a normal prompt with first starting with (env).
Trying to run the python script without first loading the source command was the problem.
I still haven't wrapped my head around how this all works but I'll keep plugging along and hopefully understand what running this command first does
source env/bin/activate
This is the command that the script uses.
sudo apt-get install python-psutil
Make sure that you are working inside the virtual environment.
If not enter into the virtual environment and give a try.
If you are still having trouble execute the following command inside the virtual environment and try again:
sudo pip3 install pathlib2
This worked for me
I am trying to make a simple python program using GTK and gstreamer. For this purpose, I need the GES (Gstreamer Editing Services) but I seem to be unable to correctly install the dependencies I need.
So far, I have installed (sudo apt-get install...) gstreamer1.0 which works fine. I have done the same thing with libges-1.0-dev and libges-1.0-0. However, when I try to import GES (from gi.repository import GES) in my python script, I get the following error:
ImportError: cannot import name GES, introspection typelib not found
I am guessing that I am missing something about how to actually install the package, but it seems that I just don't quite know my way around python and Linux as well as I should.
Run the following to verify all Prerequisites:
def Prerequisites():
import re
from subprocess import check_output, CalledProcessError, STDOUT
Desired = {'u':'Unknow', 'i':'Install', 'r':'Remove', 'h':'Hold'}
Status = {'n':'Not', 'i':'Inst', 'c':'Conf-files', 'u':'Unpacked', 'f':'halF-conf', 'h':'Half-inst', 'w':'trig-aWait', 't':'Trig-pend'}
re_pip3 = re.compile('(.+?): (.*?)\n', re.S + re.MULTILINE)
re_dpkg = re.compile('(.+?)\n', re.S + re.MULTILINE)
for n, package in enumerate(["python-gst-1.0", "python-gst-1.0", "gir1.2-gstreamer-1.0", "gir1.2-gst-plugins-base-1.0",
"gstreamer1.0-plugins-good", "gstreamer1.0-plugins-ugly", "gstreamer1.0-tools"]):
try:
if n in [0]:
output = check_output("pip3 show {}".format(package), shell=True, stderr=STDOUT).decode()
print('OK: Name: {s[Name]}, Version: {s[Version]}, Location: {s[Location]}'.
format(s=dict(re_pip3.findall(output))))
else:
output = check_output("dpkg -l {}".format(package), shell=True, stderr=STDOUT).decode()
for p in re_dpkg.findall(output)[6:]:
if p[0:2] == 'ii':
print('OK: {} - Desired:{},\tStatus:{}'.format(p, Desired[p[0]], Status[p[1]]))
else:
print('[FAIL] {} - Desired:{},\tStatus:{}'.format(p, Desired[p[0]], Status[p[1]]))
except CalledProcessError as exp:
print('[FAIL] {} - CalledProcessError: {}'.format(package, exp.output.decode()[:-1] or exp))
Please confirm that you want to do something like this: Simple
Dependencies:
* GStreamer core
* gst-plugins-base
GStreamervModules
Installing from local archives
This should be ok: "the only relevant result seems to be (gstreamer-player)"
Try the following:
from gsp import GstreamerPlayer
player = GstreamerPlayer(None)
player.queue("/path/to/audio.mp3")
The project site gives this:
Prerequisites
Debian/Ubuntu/Rasbian:
sudo apt-get install python-gst-1.0 \
gir1.2-gstreamer-1.0 gir1.2-gst-plugins-base-1.0 \
gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly \
gstreamer1.0-tools
I am able to write a script to checkout the code from SVN issue using "pysvn" module but just wanted to know is there any way I can do without pysvn also ? Because pysvn is third party library which I have to install separately on linux and windows both which I don't want. Please help me get alternate way in which I don't have to install any third party module code -
import pysvn,os,shutil
def getLogin(realm, username, may_save):
svn_user = '<my-username>'
svn_pass = '<my-password>'
return True, svn_user, svn_pass, False
def ssl_server_trust_prompt( trust_dict ):
return (True # server is trusted
,trust_dict["failures"]
,True) # save the answer so that the callback is not called again
def checkOut(svn_url,dest_dir):
if os.path.isdir(dest_dir):
shutil.rmtree(dest_dir)
os.mkdir(dest_dir)
client = pysvn.Client()
client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt
client.callback_get_login = getLogin
client.checkout(svn_url,dest_dir)
else:
os.mkdir(dest_dir)
client = pysvn.Client()
client.callback_ssl_server_trust_prompt = ssl_server_trust_prompt
client.callback_get_login = getLogin
client.checkout(svn_url,dest_dir)
print "Checking out the code hang on...\n"
checkOut('<svn-repo>','ABC')
print "checked out the code \n"
print "Checking out the code hang on...\n"
checkOut('<svn-repo>','XYZ')
print "checked out the code\n"
print "Checking out the code hang on...\n"
checkOut('<svn-repo>','MNP')
print "checked out the code \n”
You can pass username and password as arguments:
$ svn update --username 'user2' --password 'password'
You can make Executable of ur script which will include the pysvn into binary file, thus wouldn't need to import or pip install any library, n ur code will run on python-less machines too
I have a problem I'd like you to help me to solve.
I am working in Python and I want to do the following:
call an SGE batch script on a server
see if it works correctly
do something
What I do now is approx the following:
import subprocess
try:
tmp = subprocess.call(qsub ....)
if tmp != 0:
error_handler_1()
else:
correct_routine()
except:
error_handler_2()
My problem is that once the script is sent to SGE, my python script interpret it as a success and keeps working as if it finished.
Do you have any suggestion about how could I make the python code wait for the actual processing result of the SGE script ?
Ah, btw I tried using qrsh but I don't have permission to use it on the SGE
Thanks!
From your code you want the program to wait for job to finish and return code, right? If so, the qsub sync option is likely what you want:
http://gridscheduler.sourceforge.net/htmlman/htmlman1/qsub.html
Additional Answer for an easier processing:
By using the python drmaa module : link which allows a more complete processing with SGE.
A functioning code provided in the documentation is here: [provided you put a sleeper.sh script in the same directory]
please notice that the -b n option is needed to execute a .sh script, otherwise it expects a binary by default like explained here
import drmaa
import os
def main():
"""Submit a job.
Note, need file called sleeper.sh in current directory.
"""
s = drmaa.Session()
s.initialize()
print 'Creating job template'
jt = s.createJobTemplate()
jt.remoteCommand = os.getcwd()+'/sleeper.sh'
jt.args = ['42','Simon says:']
jt.joinFiles=False
jt.nativeSpecification ="-m abe -M mymail -q so-el6 -b n"
jobid = s.runJob(jt)
print 'Your job has been submitted with id ' + jobid
retval = s.wait(jobid, drmaa.Session.TIMEOUT_WAIT_FOREVER)
print('Job: {0} finished with status {1}'.format(retval.jobId, retval.hasExited))
print 'Cleaning up'
s.deleteJobTemplate(jt)
s.exit()
if __name__=='__main__':
main()