-
Notifications
You must be signed in to change notification settings - Fork 536
Description
Summary
The function interface crashes, in a code that was working in an older nipype installation (version details below). From the error, it seems I am doing something wrong when importing other functions inside of the function interface, but I don't know what it is exactly or how to fix it.
The function itself is intended to convert html into pdf and send it as an email attachment.
Actual behavior
The function below does not run, and this is the crash information:
170601-20:23:45,389 workflow INFO:
Traceback (most recent call last):
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/pipeline/plugins/multiproc.py", line 52, in run_node
result['result'] = node.run(updatehash=updatehash)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 372, in run
self._run_interface()
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 482, in _run_interface
self._result = self._run_command(execute)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 613, in _run_command
result = self._interface.run()
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1081, in run
runtime = self._run_wrapper(runtime)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1029, in _run_wrapper
runtime = self._run_interface(runtime)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/interfaces/utility/wrappers.py", line 146, in _run_interface
self.imports)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/utils/misc.py", line 102, in create_function_from_source
raise_from(RuntimeError(msg), e)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/future/utils/__init__.py", line 454, in raise_from
raise e
RuntimeError:
Error executing function:
Functions in connection strings have to be standalone.
They cannot be declared either interactively or inside
another function or inline in the connect string. Any
imports should be done inside the function
Interface Function failed to run.
170601-20:23:46,403 workflow INFO:
Traceback (most recent call last):
***********************************
File "/home/myanezl2/workspace/c3nl/QA_matlab/QA_Matlab.py", line 192, in <module>
170601-20:23:46,403 workflow ERROR:
could not run node: QA.QA_email
170601-20:23:46,404 workflow INFO:
crashfile: /home/myanezl2/workspace/c3nl/QA_matlab/crash-20170601-202344-myanezl2-QA_email-98e03d45-765c-4bec-87c5-c4e253113c83.pklz
170601-20:23:46,404 workflow INFO:
***********************************
QA.run('MultiProc', plugin_args={'n_procs': 2})
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/pipeline/engine/workflows.py", line 590, in run
runner.run(execgraph, updatehash=updatehash, config=self.config)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/pipeline/plugins/base.py", line 279, in run
report_nodes_not_run(notrun)
File "/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype/pipeline/plugins/base.py", line 101, in report_nodes_not_run
raise RuntimeError(('Workflow did not execute cleanly. '
RuntimeError: Workflow did not execute cleanly. Check log for details
Process finished with exit code 1
Expected behavior
This function was working in this previous installation:
print(nipype.version)
0.11.0
print(nipype.get_info())
{'nibabel_version': '2.0.2', 'networkx_version': '1.10', 'numpy_version': '1.11.0', 'sys_platform': 'linux2', 'sys_version': '2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec 6 2015, 18:08:32) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]', 'commit_source': '(none found)', 'commit_hash': '', 'pkg_path': '/share/apps/anaconda-3-2.4.1/lib/python2.7/site-packages/nipype', 'sys_executable': '/share/apps/anaconda-3-2.4.1/bin/python', 'traits_version': '4.5.0', 'scipy_version': '0.17.0'}
Script/Workflow details
def gen_qa_email(in_directory, empty_variable, in_date):
import os
import smtplib
import pdfkit
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
""" Convert html to pdf"""
pdf_file = pdfkit.from_file(in_directory + '/QA_results.html', False)
""" Create the email message container from the input args."""
recipients = ['[email protected]']
msg = MIMEMultipart('alternative')
msg['Subject'] = 'QA' + in_date
msg['From'] = '[email protected]'
msg['To'] = ", ".join(recipients)
""" Attach parts into message container"""
pdf = MIMEApplication(pdf_file, 'pdf')
pdf.add_header('Content-Disposition', 'attachment', filename= 'QA.pdf')
msg.attach(pdf)
try:
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(''[email protected]']', 'password')
smtpserver.sendmail(''[email protected]'], recipients, msg.as_string())
smtpserver.quit()
except smtplib.SMTPAuthenticationError as e:
print "Unable to send message: %s" % e
return None
QA_email = Node(name='QA_email', interface=Function(input_names=['in_directory', 'empty_variable', 'in_date'], output_names=[], function=gen_qa_email))
QA_email.inputs.in_date = experiment_date
Platform details:
print(nipype.version)
0.13.1
print(nipype.get_info())
{'nibabel_version': '2.1.0', 'sys_executable': '/apps/software/anaconda/4.3.1/bin/python', 'networkx_version': '1.11', 'numpy_version': '1.11.3', 'sys_platform': 'linux2', 'sys_version': '2.7.13 |Anaconda 4.3.1 (64-bit)| (default, Dec 20 2016, 23:09:15) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]', 'commit_source': u'installation', 'commit_hash': u'8946bcab9', 'pkg_path': '/apps/software/anaconda/4.3.1/lib/python2.7/site-packages/nipype', 'nipype_version': u'0.13.1', 'traits_version': '4.6.0', 'scipy_version': '0.18.1'}