diff --git a/node_import.inc b/node_import.inc
index 6389f6e..171fede 100644
--- a/node_import.inc
+++ b/node_import.inc
@@ -859,7 +859,7 @@ function node_import_do_task(&$task, $unit = 'all', $count = 0) {
   global $node_import_can_continue;
   $node_import_can_continue = TRUE;
 
-  if ($task['status'] != NODE_IMPORT_STATUS_DONE && node_import_lock_acquire()) {
+  if ($task['status'] != NODE_IMPORT_STATUS_DONE && node_import_lock_acquire($task['taskid'])) {
     global $user;
     $backup_user = $user;
     if ($task['uid'] != $user->uid) {
@@ -887,6 +887,7 @@ function node_import_do_task(&$task, $unit = 'all', $count = 0) {
 
       case NODE_IMPORT_STATUS_ERROR:
         $task['status'] = NODE_IMPORT_STATUS_DONE;
+        node_import_lock_acquire($task['taskid'], TRUE);
         $file_offset = $task['file']->filesize; //TODO
         break;
     }
@@ -930,6 +931,7 @@ function node_import_do_task(&$task, $unit = 'all', $count = 0) {
       else {
         db_query("UPDATE {node_import_tasks} SET status = %d, file_offset = %d WHERE taskid = %d", NODE_IMPORT_STATUS_DONE, $task['file']->filesize, $taskid);
         $task['status'] = NODE_IMPORT_STATUS_DONE;
+        node_import_lock_acquire($task['taskid'], TRUE);
         $task['file_offset'] = $task['file']->filesize;
       }
 
@@ -949,7 +951,6 @@ function node_import_do_task(&$task, $unit = 'all', $count = 0) {
           || ($unit == 'ms' && timer_read('node_import:do_task:'. $taskid) < $count))) {
         continue;
       }
-
       break;
     }
 
@@ -959,7 +960,7 @@ function node_import_do_task(&$task, $unit = 'all', $count = 0) {
     $user = $backup_user;
     session_save_session(TRUE);
     timer_stop('node_import:do_task:'. $taskid);
-    node_import_lock_release();
+    node_import_lock_acquire($task['taskid'], TRUE);
   }
 }
 
@@ -2153,29 +2154,10 @@ function node_import_drupal_validate_form($form_id, $form, &$form_state) {
  */
 
 /**
- * @defgroup node_import_locking Node import locking functions
- * @{
- * Locking functions for node_import. This code is based on #251792
- * (Implement a locking framework for long operations). We need
- * locking to avoid both hook_cron() and node_import_view_form() to
- * process the same task at the same time (which would result in
- * rows being processed twice).
- *
- * The code below uses the database-based locking mechanism. Note
- * that is does not use the full implementation as in the patch
- * because we can have only one global lock. One lock for each task
- * does not work because a task can spawn the creation of something
- * else (such as a taxonomy term).
- *
- * We only need one _acquire() and _release() function.
- *
- * When a more general locking framework is committed to Drupal,
- * we can easily replace this.
- */
-
-/**
  * Acquire or release our node_import lock.
  *
+ * @param $taskid
+ *
  * @param $release
  *   Boolean. If TRUE, release the lock. If FALSE, acquire the
  *   lock.
@@ -2183,39 +2165,19 @@ function node_import_drupal_validate_form($form_id, $form, &$form_state) {
  * @return
  *   Boolean. Whether the lock was acquired.
  */
-function node_import_lock_acquire($release = FALSE) {
-  static $lock_id, $locked;
-
-  if (!isset($lock_id)) {
-    $lock_id = md5(uniqid());
-    $locked = FALSE;
-    register_shutdown_function('node_import_lock_release');
+function node_import_lock_acquire($taskid, $release = FALSE) {
+  $locked = variable_get('node_import:locked', array());
+  if (!empty($locked[$taskid])) {
+    return FALSE;
   }
-
-  if ($release) {
-    db_query("DELETE FROM {variable} WHERE name = '%s'", 'node_import:lock');
-    $locked = FALSE;
+  elseif (!empty($release)) {
+    unset($locked[$taskid]);
+    variable_set('node_import:locked', $locked);
+    return FALSE;
   }
-  else if (!$locked) {
-    if (@db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'node_import:lock', $lock_id)) {
-      $locked = TRUE;
-    }
+  else {
+    $locked[$taskid] = TRUE;
   }
-
-  return $locked;
-}
-
-/**
- * Release our node_import lock.
- *
- * @return
- *   Nothing.
- */
-function node_import_lock_release() {
-  node_import_lock_acquire(TRUE);
-}
-
-/**
- * @}
- */
-
+  variable_set('node_import:locked', $locked);
+  return $locked[$taskid];
+}
\ No newline at end of file
