# Code getting hanged or Killed constantly

**URL:** https://discuss.ray.io/t/code-getting-hanged-or-killed-constantly/5055
**Category:** Ray Core
**Created:** [February 14, 2022, 12:55pm UTC](https://discuss.ray.io/t/code-getting-hanged-or-killed-constantly/5055 "2022-02-14T12:55:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Aditi\_Bhalawat](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/aditi_bhalawat/32/2071_2.png) [@Aditi\_Bhalawat](https://discuss.ray.io/u/Aditi_Bhalawat)
#### Post date: [February 14, 2022, 12:55pm UTC](https://discuss.ray.io/t/code-getting-hanged-or-killed-constantly/5055/1 "2022-02-14T12:55:18Z")

</div>

```auto
def mongo(contractAddress, block):
    Block_Address = pymongo.MongoClient(connection_Url).get_database('Holders').Block_Address
    if Block_Address.find_one({'contractAddress': contractAddress}) == None:
        Block_Address.insert_one({
                  'contractAddress': contractAddress,
                  'Block': block
                })

@ray.remote
def contract(_block):
    web3 = Web3(Web3.WebsocketProvider(infuraURL))
    for i in range(len(web3.eth.get_block(_block).transactions)):
    address = web3.eth.getTransactionReceipt(web3.eth.get_block(_block).transactions[i].hex()).contractAddress
    if address != None:
        mongo(address, _block)

if __name__ ==" __main__":
    ray.init(address='auto')
    print('''This cluster consists of
    {} nodes in total
    {} CPU resources in total
    '''.format(len(ray.nodes()), ray.cluster_resources()['CPU']))
    web3 = Web3(Web3.WebsocketProvider(infura_url))
    latestBlock = web3.eth.get_block('latest').number
    del web3
    del infura_url
    ray.get([contract.remote(block) for block in reversed(range(latestBlock))])

```

I am not able to figure out why code is getting killed and sometime system gets hanged.

Could anyone provide some help

---

<div class="post-metadata">

### Author: ![yic](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yic/32/437_2.png) [@yic](https://discuss.ray.io/u/yic)
#### Post date: [February 14, 2022, 8:00pm UTC](https://discuss.ray.io/t/code-getting-hanged-or-killed-constantly/5055/2 "2022-02-14T20:00:09Z")

</div>

Hi @Aditi_Bhalawat there is no way for us to know what’s happening here by just reading the code you provided.

Could you 1) format your code with indent; 2) check the logs either in the console and `/tmp/ray/session_latest/logs` and provide more information about your case?

---

<div class="post-metadata">

### Author: ![Aditi\_Bhalawat](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/aditi_bhalawat/32/2071_2.png) [@Aditi\_Bhalawat](https://discuss.ray.io/u/Aditi_Bhalawat)
#### Post date: [February 15, 2022, 5:21am UTC](https://discuss.ray.io/t/code-getting-hanged-or-killed-constantly/5055/3 "2022-02-15T05:21:50Z")

</div>

I added indent in the code.  
And what is happening with code is that it runs for few minute and after the it stops and gives output as

`killed`

or the machine gets hanged.  
I am not able to understand why is it happening like this.

---

<div class="post-metadata">

### Author: ![yic](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yic/32/437_2.png) [@yic](https://discuss.ray.io/u/yic)
#### Post date: [February 15, 2022, 7:40pm UTC](https://discuss.ray.io/t/code-getting-hanged-or-killed-constantly/5055/4 "2022-02-15T19:40:26Z")

</div>

Thanks for helping improve the code. Could you also check `/tmp/ray/session_latest/logs` to see whether something is broken?

Btw, I think this might not be related to ray. Could you also check whether the program OOM? Usually, when OOM killer got triggered, it’ll show `killed` or machine hangs. `dmesg` might give you some insights.

---

<div class="post-metadata">

### Author: ![Aditi\_Bhalawat](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/aditi_bhalawat/32/2071_2.png) [@Aditi\_Bhalawat](https://discuss.ray.io/u/Aditi_Bhalawat)
#### Post date: [February 15, 2022, 7:42pm UTC](https://discuss.ray.io/t/code-getting-hanged-or-killed-constantly/5055/5 "2022-02-15T19:42:50Z")

</div>

> [@yic](#):
>
> dmesg

Could you tell me where to check logs ? And also how to check whether the program is OOM
